diff --git a/ChangeLog b/ChangeLog index 99f1b2ace..e4a7887b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ Changes in versino 0.1.2.20 - 2008-??-?? Resolves bug 597. - Fix a few memory leaks that could in theory happen under bizarre error conditions. + - We were leaking a file descriptor if Tor started with a zero-length + cached-descriptors file. Patch by freddy77. Changes in version 0.1.2.19 - 2008-01-17 diff --git a/src/common/compat.c b/src/common/compat.c index 71ac5d5e0..013956446 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -158,19 +158,18 @@ tor_mmap_file(const char *filename) /* Zero-length file. If we call mmap on it, it will succeed but * return NULL, and bad things will happen. So just fail. */ log_info(LD_FS,"File \"%s\" is empty. Ignoring.",filename); + close(fd); return NULL; } string = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (string == MAP_FAILED) { - close(fd); log_warn(LD_FS,"Could not mmap file \"%s\": %s", filename, strerror(errno)); return NULL; } - close(fd); - res = tor_malloc_zero(sizeof(tor_mmap_impl_t)); res->base.data = string; res->base.size = filesize;