[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Small leak patch
I discovered a small fd leak in src/common/compat.c:tor_mmap_file
diff
-r -U10 tor-0.1.2.19/src/common/compat.c tor-0.1.2.19.
my/src/common/compat.c
--- tor-0.1.2.19/src/common/compat.c 2008-01-
08 05:45:55.000000000 +0100
+++ tor-0.1.2.19.my/src/common/compat.c
2008-02-12 09:41:24.211311798 +0100
@@ -148,36 +148,35 @@
return
NULL;
}
size = filesize = (size_t) lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
/* ensure page alignment */
page_size =
getpagesize();
size += (size%page_size) ? page_size-(size%page_size)
: 0;
if (!size) {
+ close(fd);
/* 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);
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;
res->mapping_size = size;
return &(res->base);
}
/**
Release storage held for a memory mapping. */
void
tor_munmap_file
(tor_mmap_t *handle)
If file is zero fd was not released.
bye
freddy77