OSDN Git Service

openjdkjvm: Don't leak the results of JVM_RawMonitorCreate.
authorNarayan Kamath <narayan@google.com>
Tue, 9 Feb 2016 13:11:09 +0000 (13:11 +0000)
committerNarayan Kamath <narayan@google.com>
Tue, 9 Feb 2016 14:03:33 +0000 (14:03 +0000)
bug: 27050501

Change-Id: Ib0db3e5a1ec412de07455f09fe88b3102b347e46

runtime/openjdkjvm/OpenjdkJvm.cc

index 487b7d8..725067a 100644 (file)
@@ -124,14 +124,18 @@ JNIEXPORT jlong JVM_Lseek(jint fd, jlong offset, jint whence) {
  * mutexes.  They're used by ZipFile.
  */
 JNIEXPORT void* JVM_RawMonitorCreate(void) {
-    pthread_mutex_t* newMutex =
+    pthread_mutex_t* mutex =
         reinterpret_cast<pthread_mutex_t*>(malloc(sizeof(pthread_mutex_t)));
-    pthread_mutex_init(newMutex, NULL);
-    return newMutex;
+    CHECK(mutex != nullptr);
+    CHECK_PTHREAD_CALL(pthread_mutex_init, (mutex, nullptr), "JVM_RawMonitorCreate");
+    return mutex;
 }
 
 JNIEXPORT void JVM_RawMonitorDestroy(void* mon) {
-    pthread_mutex_destroy(reinterpret_cast<pthread_mutex_t*>(mon));
+    CHECK_PTHREAD_CALL(pthread_mutex_destroy,
+                       (reinterpret_cast<pthread_mutex_t*>(mon)),
+                       "JVM_RawMonitorDestroy");
+    free(mon);
 }
 
 JNIEXPORT jint JVM_RawMonitorEnter(void* mon) {
@@ -139,7 +143,9 @@ JNIEXPORT jint JVM_RawMonitorEnter(void* mon) {
 }
 
 JNIEXPORT void JVM_RawMonitorExit(void* mon) {
-    pthread_mutex_unlock(reinterpret_cast<pthread_mutex_t*>(mon));
+    CHECK_PTHREAD_CALL(pthread_mutex_unlock,
+                       (reinterpret_cast<pthread_mutex_t*>(mon)),
+                       "JVM_RawMonitorExit");
 }
 
 JNIEXPORT char* JVM_NativePath(char* path) {