8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
authorjzavgren
Tue, 20 Nov 2012 09:26:38 +0000
changeset 14517 e50acb436a8d
parent 14516 51de2e3a1037
child 14518 f4b1adde53b3
8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code Reviewed-by: dsamersoff, valeriep, chegar
jdk/src/share/bin/wildcard.c
jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c
jdk/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c
jdk/src/solaris/bin/java_md_solinux.c
--- a/jdk/src/share/bin/wildcard.c	Mon Nov 19 13:17:40 2012 +0000
+++ b/jdk/src/share/bin/wildcard.c	Tue Nov 20 09:26:38 2012 +0000
@@ -356,8 +356,13 @@
     const char *basename;
     FileList fl = FileList_new(16);
     WildcardIterator it = WildcardIterator_for(wildcard);
+
     if (it == NULL)
+    {
+        FileList_free(fl);
         return NULL;
+    }
+
     while ((basename = WildcardIterator_next(it)) != NULL)
         if (isJarFileName(basename))
             FileList_add(fl, wildcardConcat(wildcard, basename));
--- a/jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Mon Nov 19 13:17:40 2012 +0000
+++ b/jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Tue Nov 20 09:26:38 2012 +0000
@@ -571,7 +571,7 @@
  */
 void inquireCred(JNIEnv *env, jobject jobj, gss_cred_id_t pCred,
                  jint type, void *result) {
-  OM_uint32 minor, major=GSS_C_QOP_DEFAULT;
+  OM_uint32 minor, major=0;
   OM_uint32 routineErr;
   gss_cred_id_t credHdl;
 
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c	Mon Nov 19 13:17:40 2012 +0000
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_mutex.c	Tue Nov 20 09:26:38 2012 +0000
@@ -112,22 +112,34 @@
     ckpInitArgs->UnlockMutex = NULL_PTR;
 #else
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "CreateMutex", "Lsun/security/pkcs11/wrapper/CK_CREATEMUTEX;");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID);
     ckpInitArgs->CreateMutex = (jMutexHandler != NULL) ? &callJCreateMutex : NULL_PTR;
 
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "DestroyMutex", "Lsun/security/pkcs11/wrapper/CK_DESTROYMUTEX;");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID);
     ckpInitArgs->DestroyMutex = (jMutexHandler != NULL) ? &callJDestroyMutex : NULL_PTR;
 
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "LockMutex", "Lsun/security/pkcs11/wrapper/CK_LOCKMUTEX;");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID);
     ckpInitArgs->LockMutex = (jMutexHandler != NULL) ? &callJLockMutex : NULL_PTR;
 
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "UnlockMutex", "Lsun/security/pkcs11/wrapper/CK_UNLOCKMUTEX;");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jMutexHandler = (*env)->GetObjectField(env, jInitArgs, fieldID);
     ckpInitArgs->UnlockMutex = (jMutexHandler != NULL) ? &callJUnlockMutex : NULL_PTR;
 
@@ -151,13 +163,19 @@
 
     /* convert and set the flags field */
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "flags", "J");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jFlags = (*env)->GetLongField(env, jInitArgs, fieldID);
     ckpInitArgs->flags = jLongToCKULong(jFlags);
 
     /* pReserved should be NULL_PTR in this version */
     fieldID = (*env)->GetFieldID(env, jInitArgsClass, "pReserved", "Ljava/lang/Object;");
-    if (fieldID == NULL) { return NULL; }
+    if (fieldID == NULL) {
+        free(ckpInitArgs);
+        return NULL;
+    }
     jReserved = (*env)->GetObjectField(env, jInitArgs, fieldID);
 
     /* we try to convert the reserved parameter also */
--- a/jdk/src/solaris/bin/java_md_solinux.c	Mon Nov 19 13:17:40 2012 +0000
+++ b/jdk/src/solaris/bin/java_md_solinux.c	Tue Nov 20 09:26:38 2012 +0000
@@ -478,9 +478,11 @@
         JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE");
 
         if (mustsetenv == JNI_FALSE) {
+            JLI_MemFree(newargv);
             return;
         }
 #else
+        JLI_MemFree(newargv);
         return;
 #endif /* SETENV_REQUIRED */
       } else {  /* do the same speculatively or exit */