aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-05-23 12:39:05 -0400
committerNick Mathewson <nickm@torproject.org>2012-05-23 12:39:05 -0400
commitab1b81e838150ae070b1c6818b9c95faeea56c06 (patch)
tree34f8de513fb1081b717f9477cfa79fd8f35498fb /src/common/compat.c
parent75fc4dbbcabaedc715f0f9e883ccab1c9634e787 (diff)
downloadtor-ab1b81e838150ae070b1c6818b9c95faeea56c06.tar
tor-ab1b81e838150ae070b1c6818b9c95faeea56c06.tar.gz
Close the windows file handle after CreateFileMapping; it isn't needed
I did the changes file; the rest came pseudonymously
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index a4e50747c..3174da647 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -175,24 +175,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,
+ 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);
@@ -200,7 +200,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
@@ -218,6 +218,7 @@ tor_mmap_file(const char *filename)
if (!res->data)
goto win_err;
+ CloseHandle(file_handle);
return res;
win_err: {
DWORD e = GetLastError();
@@ -234,6 +235,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;
}
@@ -247,8 +250,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