diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-12-07 14:39:42 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-12-07 14:39:42 +0000 |
commit | e8dc71ade4fcf2de0f6f411a1c8d1804b7dc3358 (patch) | |
tree | af19e7baf164f49ea46ac9e8192d9db5c3bb43b7 /src/common | |
parent | 65b14eae90059578714e6558c558b170c5671bed (diff) | |
download | tor-e8dc71ade4fcf2de0f6f411a1c8d1804b7dc3358.tar.gz tor-e8dc71ade4fcf2de0f6f411a1c8d1804b7dc3358.zip |
r11444@Kushana: nickm | 2006-12-07 09:38:52 -0500
Fix a couple of obvious bugs in tor_mmap_file on Windows: first, fix a boolean error when checking the return value of CreateFileMapping. Second, CreateFileMapping is documented to return NULL on failure.
svn:r9035
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 3156adea87..58f1dfdd10 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -183,7 +183,8 @@ tor_mmap_t * tor_mmap_file(const char *filename) { win_mmap_t *res = tor_malloc_zero(sizeof(win_mmap_t)); - res->mmap_handle = res->file_handle = INVALID_HANDLE_VALUE; + res->file_handle = INVALID_HANDLE_VALUE; + res->mmap_handle = NULL; res->file_handle = CreateFile(filename, GENERIC_READ, @@ -207,7 +208,7 @@ tor_mmap_file(const char *filename) #endif (res->base.size & 0xfffffffful), NULL); - if (res->mmap_handle != INVALID_HANDLE_VALUE) + if (res->mmap_handle == NULL) goto err; res->base.data = (char*) MapViewOfFile(res->mmap_handle, FILE_MAP_READ, @@ -226,12 +227,11 @@ tor_munmap_file(tor_mmap_t *handle) win_mmap_t *h = (win_mmap_t*) (((char*)handle) - STRUCT_OFFSET(win_mmap_t, base)); if (handle->data) - - /*this is an ugly cast, but without it, "data" in struct tor_mmap_t would - have to be redefined as const*/ + /* This is an ugly cast, but without it, "data" in struct tor_mmap_t would + have to be redefined as non-const. */ UnmapViewOfFile( (LPVOID) handle->data); - if (h->mmap_handle != INVALID_HANDLE_VALUE) + if (h->mmap_handle != NULL) CloseHandle(h->mmap_handle); if (h->file_handle != INVALID_HANDLE_VALUE) CloseHandle(h->file_handle); |