diff options
author | Roger Dingledine <arma@torproject.org> | 2008-02-13 07:23:37 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2008-02-13 07:23:37 +0000 |
commit | 740097a65ed5c92b3a5a23f0c919b82ea6a59625 (patch) | |
tree | 7b65e5f3246fb3cdbbede06e3bc247f65255e31f /src | |
parent | 7ae3f6a491c96182eab243a53a582532c415cea7 (diff) | |
download | tor-740097a65ed5c92b3a5a23f0c919b82ea6a59625.tar.gz tor-740097a65ed5c92b3a5a23f0c919b82ea6a59625.zip |
We were leaking a file descriptor if Tor started with a zero-length
cached-descriptors file. Patch by freddy77; bugfix on 0.1.2.
svn:r13488
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compat.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index cc8350d4a0..b1b18fa7ab 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -129,6 +129,7 @@ typedef struct tor_mmap_impl_t { size_t mapping_size; /**< Size of the actual mapping. (This is this file * size, rounded up to the nearest page.) */ } tor_mmap_impl_t; + /** Try to create a memory mapping for <b>filename</b> and return it. On * failure, return NULL. Sets errno properly, using ERANGE to mean * "empty file". */ @@ -164,21 +165,20 @@ tor_mmap_file(const char *filename) * return NULL, and bad things will happen. So just fail. */ log_info(LD_FS,"File \"%s\" is empty. Ignoring.",filename); errno = ERANGE; + close(fd); return NULL; } string = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (string == MAP_FAILED) { int save_errno = errno; - close(fd); log_warn(LD_FS,"Could not mmap file \"%s\": %s", filename, strerror(errno)); errno = save_errno; return NULL; } - close(fd); - res = tor_malloc_zero(sizeof(tor_mmap_impl_t)); res->base.data = string; res->base.size = filesize; |