OSDN Git Service

Release resources when repeating dlopen-dlcose.
authorzhongjie <zhongjie.shi@intel.com>
Wed, 9 Mar 2016 07:05:04 +0000 (15:05 +0800)
committerzhongjie <zhongjie.shi@intel.com>
Wed, 9 Mar 2016 07:17:14 +0000 (15:17 +0800)
When the libbinder.so is dlopen and dlclose many
times, we need to delete the pthread_key and
munmap the memory mapping.

Otherwise, it will crash as the leakage causes
the pthread_key or memory mapping surpass their
limit.

Change-Id: Ice64d4ef685c1f665350286f9e5ddf790beac236
Signed-off-by: zhongjie <zhongjie.shi@intel.com>
libs/binder/IPCThreadState.cpp
libs/binder/ProcessState.cpp

index 1f6bda2..6d4071e 100644 (file)
@@ -328,6 +328,7 @@ void IPCThreadState::shutdown()
             delete st;
             pthread_setspecific(gTLS, NULL);
         }
+        pthread_key_delete(gTLS);
         gHaveTLS = false;
     }
 }
index 33fe26c..5114ac1 100644 (file)
@@ -364,6 +364,13 @@ ProcessState::ProcessState()
 
 ProcessState::~ProcessState()
 {
+    if (mDriverFD >= 0) {
+        if (mVMStart != MAP_FAILED) {
+            munmap(mVMStart, BINDER_VM_SIZE);
+        }
+        close(mDriverFD);
+    }
+    mDriverFD = -1;
 }
         
 }; // namespace android