Bug 1044193 - Always cleanup on heap allocation path. r=glandium, a=lmandel
authorMichael Wu <mwu@mozilla.com>
Tue, 05 Aug 2014 02:19:59 -0400
changeset 208264 e51295fe2c54
parent 208263 551f71d3138f
child 208265 599c7756380c
push id3794
push userryanvm@gmail.com
push date2014-08-07 20:40 +0000
treeherdermozilla-beta@599c7756380c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, lmandel
bugs1044193
milestone32.0
Bug 1044193 - Always cleanup on heap allocation path. r=glandium, a=lmandel
memory/mozalloc/VolatileBufferAshmem.cpp
--- a/memory/mozalloc/VolatileBufferAshmem.cpp
+++ b/memory/mozalloc/VolatileBufferAshmem.cpp
@@ -47,27 +47,31 @@ VolatileBuffer::Init(size_t aSize, size_
   }
 
   mFd = open("/" ASHMEM_NAME_DEF, O_RDWR);
   if (mFd < 0) {
     goto heap_alloc;
   }
 
   if (ioctl(mFd, ASHMEM_SET_SIZE, mSize) < 0) {
-    close(mFd);
-    mFd = -1;
     goto heap_alloc;
   }
 
   mBuf = mmap(nullptr, mSize, PROT_READ | PROT_WRITE, MAP_SHARED, mFd, 0);
   if (mBuf != MAP_FAILED) {
     return true;
   }
 
 heap_alloc:
+  mBuf = nullptr;
+  if (mFd >= 0) {
+    close(mFd);
+    mFd = -1;
+  }
+
 #ifdef MOZ_MEMORY
 #ifdef MOZ_WIDGET_ANDROID
   __wrap_posix_memalign(&mBuf, aAlignment, aSize);
 #else
   posix_memalign(&mBuf, aAlignment, aSize);
 #endif
 #else
   mBuf = memalign(aAlignment, aSize);