diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-05-31 12:38:11 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-05-31 12:38:11 -0400 |
commit | 0e207f9acb655d037c8aef86ea2781d8e1b4b570 (patch) | |
tree | bd5a76c50efb48bcdab5fd98994aa40a9c70c97c | |
parent | f1aae1236fc68a0047ac9370bdcf828a42efdab3 (diff) | |
parent | 2e58882b90a5015554b59862869b20dba39a5d58 (diff) | |
download | tor-0e207f9acb655d037c8aef86ea2781d8e1b4b570.tar.gz tor-0e207f9acb655d037c8aef86ea2781d8e1b4b570.zip |
Merge remote-tracking branch 'public/close_file_mapping'
Conflicts:
src/common/compat.h
Conflict was between replacement of MS_WINDOWS with _WIN32 in
master, and with removal of file_handle from tor_mmap_t struct in
close_file_mapping branch (for bug 5951 fix).
-rw-r--r-- | changes/close_file_handle | 4 | ||||
-rw-r--r-- | src/common/compat.c | 25 | ||||
-rw-r--r-- | src/common/compat.h | 1 |
3 files changed, 17 insertions, 13 deletions
diff --git a/changes/close_file_handle b/changes/close_file_handle new file mode 100644 index 0000000000..128ef81987 --- /dev/null +++ b/changes/close_file_handle @@ -0,0 +1,4 @@ + o Minor bugfixes: + - Don't hold a windows file handle open for every file mapping; + the file mapping handle is sufficient. Fix for bug 5951; bugfix on + 0.1.2.1-alpha. diff --git a/src/common/compat.c b/src/common/compat.c index 0021f9290c..59c7ca4c5a 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -227,24 +227,24 @@ tor_mmap_file(const char *filename) TCHAR tfilename[MAX_PATH]= {0}; tor_mmap_t *res = tor_malloc_zero(sizeof(tor_mmap_t)); int empty = 0; - res->file_handle = INVALID_HANDLE_VALUE; + HANDLE file_handle = INVALID_HANDLE_VALUE; res->mmap_handle = NULL; #ifdef UNICODE mbstowcs(tfilename,filename,MAX_PATH); #else strlcpy(tfilename,filename,MAX_PATH); #endif - res->file_handle = CreateFile(tfilename, - GENERIC_READ, FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - 0); + file_handle = CreateFile(tfilename, + GENERIC_READ, FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); - if (res->file_handle == INVALID_HANDLE_VALUE) + if (file_handle == INVALID_HANDLE_VALUE) goto win_err; - res->size = GetFileSize(res->file_handle, NULL); + res->size = GetFileSize(file_handle, NULL); if (res->size == 0) { log_info(LD_FS,"File \"%s\" is empty. Ignoring.",filename); @@ -252,7 +252,7 @@ tor_mmap_file(const char *filename) goto err; } - res->mmap_handle = CreateFileMapping(res->file_handle, + res->mmap_handle = CreateFileMapping(file_handle, NULL, PAGE_READONLY, #if SIZEOF_SIZE_T > 4 @@ -270,6 +270,7 @@ tor_mmap_file(const char *filename) if (!res->data) goto win_err; + CloseHandle(file_handle); return res; win_err: { DWORD e = GetLastError(); @@ -286,6 +287,8 @@ tor_mmap_file(const char *filename) err: if (empty) errno = ERANGE; + if (file_handle != INVALID_HANDLE_VALUE) + CloseHandle(file_handle); tor_munmap_file(res); return NULL; } @@ -299,8 +302,6 @@ tor_munmap_file(tor_mmap_t *handle) if (handle->mmap_handle != NULL) CloseHandle(handle->mmap_handle); - if (handle->file_handle != INVALID_HANDLE_VALUE) - CloseHandle(handle->file_handle); tor_free(handle); } #else diff --git a/src/common/compat.h b/src/common/compat.h index 7edd889ee3..7ba350945a 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -247,7 +247,6 @@ typedef struct tor_mmap_t { size_t mapping_size; /**< Size of the actual mapping. (This is this file * size, rounded up to the nearest page.) */ #elif defined _WIN32 - HANDLE file_handle; HANDLE mmap_handle; #endif |