[or-cvs] r13488: We were leaking a file descriptor if Tor started with a zero (in tor/trunk: . src/common)

arma at seul.org arma at seul.org
Wed Feb 13 07:23:37 UTC 2008


Author: arma
Date: 2008-02-13 02:23:37 -0500 (Wed, 13 Feb 2008)
New Revision: 13488

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/common/compat.c
Log:
We were leaking a file descriptor if Tor started with a zero-length
cached-descriptors file. Patch by freddy77; bugfix on 0.1.2.


Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-02-12 22:21:20 UTC (rev 13487)
+++ tor/trunk/ChangeLog	2008-02-13 07:23:37 UTC (rev 13488)
@@ -13,6 +13,8 @@
     - Directory mirrors no longer include a guess at the client's IP
       address if the connection appears to be coming from the same /24
       network; it was producing too many wrong guesses.
+    - We were leaking a file descriptor if Tor started with a zero-length
+      cached-descriptors file. Patch by freddy77; bugfix on 0.1.2.
 
 
 Changes in version 0.2.0.19-alpha - 2008-02-09

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2008-02-12 22:21:20 UTC (rev 13487)
+++ tor/trunk/src/common/compat.c	2008-02-13 07:23:37 UTC (rev 13488)
@@ -129,6 +129,7 @@
   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 @@
      * 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;



More information about the tor-commits mailing list