8014307: Memory leak ... security/jgss/wrapper/GSSLibStub.c
authorjzavgren
Fri, 14 Jun 2013 09:13:03 -0400
changeset 18175 4ed91d93ab81
parent 18174 806bf0d6f0c7
child 18176 054c21148a53
8014307: Memory leak ... security/jgss/wrapper/GSSLibStub.c Summary: I modified the native procedure: Java_sun_security_jgss_wrapper_GSSLibStub_initContext() so that allocated memory is freed when errors occur. Reviewed-by: chegar, valeriep
jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c
--- a/jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Thu Jun 13 17:48:11 2013 -0700
+++ b/jdk/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Fri Jun 14 09:13:03 2013 -0400
@@ -329,6 +329,8 @@
   initGSSBuffer(env, jnameVal, &nameVal);
   nameType = newGSSOID(env, jnameType);
   if ((*env)->ExceptionCheck(env)) {
+    deleteGSSOID(nameType);
+    resetGSSBuffer(env, jnameVal, &nameVal);
     return jlong_zero;
   }
 
@@ -823,6 +825,7 @@
                                         FID_NativeGSSContext_lifetime));
   cb = getGSSCB(env, jcb);
   if ((*env)->ExceptionCheck(env)) {
+    free(cb);
     return NULL;
   }
 
@@ -927,6 +930,8 @@
   initGSSBuffer(env, jinToken, &inToken);
   cb = getGSSCB(env, jcb);
   if ((*env)->ExceptionCheck(env)) {
+    free(cb);
+    resetGSSBuffer(env, jinToken, &inToken);
     return NULL;
   }
   srcName = GSS_C_NO_NAME;
@@ -979,6 +984,7 @@
 
       /* return immediately if an exception has occurred */
       if ((*env)->ExceptionCheck(env)) {
+        resetGSSBuffer(env, jinToken, &inToken);
         return NULL;
       }
       sprintf(debugBuf, "[GSSLibStub_acceptContext] set targetName=%ld",
@@ -993,6 +999,7 @@
                                    ptr_to_jlong(srcName), jobj);
       /* return immediately if an exception has occurred */
       if ((*env)->ExceptionCheck(env)) {
+        resetGSSBuffer(env, jinToken, &inToken);
         return NULL;
       }
       sprintf(debugBuf, "[GSSLibStub_acceptContext] set srcName=%ld",
@@ -1019,6 +1026,7 @@
                                      ptr_to_jlong(delCred), jsrcName, jMech);
         /* return immediately if an exception has occurred */
         if ((*env)->ExceptionCheck(env)) {
+          resetGSSBuffer(env, jinToken, &inToken);
           return NULL;
         }
         (*env)->SetObjectField(env, jcontextSpi,