Bug 679612 - Add fclose calls to every exit point in APKOpen.cpp to prevent resource leaks; r=mwu
authorAtul Aggarwal <atulagrwl@gmail.com>
Wed, 31 Aug 2011 16:30:33 +0100
changeset 76331 1cd7272274401940f88cb3a311c1ba5973585726
parent 76330 7670696cd7003111557663dfac0940f431666362
child 76332 0504a441fef78c7d247270b6296760e3af062aa9
push id21097
push userbmo@edmorley.co.uk
push dateThu, 01 Sep 2011 07:45:07 +0000
treeherdermozilla-central@7d3d1c2c75f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs679612
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 679612 - Add fclose calls to every exit point in APKOpen.cpp to prevent resource leaks; r=mwu
other-licenses/android/APKOpen.cpp
--- a/other-licenses/android/APKOpen.cpp
+++ b/other-licenses/android/APKOpen.cpp
@@ -286,16 +286,17 @@ extractFile(const char * path, const str
     __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't open %s to decompress library", path);
     return;
   }
 
   void * buf = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   if (buf == (void *)-1) {
     __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't mmap decompression buffer");
+    close(fd);
     return;
   }
 
   z_stream strm = {
     next_in: (Bytef *)data,
     avail_in: letoh32(entry->compressed_size),
     total_in: 0,
 
@@ -505,20 +506,22 @@ static void * mozload(const char * path,
       fd = open(fullpath, O_RDWR | O_CREAT);
       if (fd < 0) {
         __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't create a file either, giving up");
         return NULL;
       }
       // we'd like to use fallocate here, but it doesn't exist currently?
       if (lseek(fd, lib_size - 1, SEEK_SET) == (off_t) - 1) {
          __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "seeking file failed");
+        close(fd);
         return NULL;
       }
       if (write(fd, "", 1) != 1) {
         __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "writting one byte to the file failed");
+        close(fd);
         return NULL;
       }
       skipLibCache = true;
       addLibCacheFd(path + 4, fd);
     }
     buf = mmap(NULL, lib_size,
                PROT_READ | PROT_WRITE,
                MAP_SHARED, fd, 0);