8155211: Ucrypto Library leaks native memory
authorstuefe
Sat, 07 May 2016 00:26:02 +0000
changeset 37804 3d485fe01521
parent 37803 ac955d7f5271
child 37806 de13122a9255
8155211: Ucrypto Library leaks native memory Summary: Free the memory allocated by calloc(0, x) calls Reviewed-by: valeriep, igerasim
jdk/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c
--- a/jdk/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c	Fri May 06 14:03:08 2016 -0700
+++ b/jdk/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c	Sat May 07 00:26:02 2016 +0000
@@ -650,6 +650,7 @@
   unsigned char *bufIn;
   unsigned char *bufOut;
   int outLen, rv = 0;
+  jint rc;
 
   context = (crypto_ctx_t *) contextID;
 
@@ -668,22 +669,20 @@
   }
   rv = CipherFinal(context, encrypt, bufOut, 0, &outLen);
   if (rv) {
-    free(context);
-    if (outLen != 0) {
-      free(bufOut);
-    }
-    return -rv;
+    rc = -rv;
   } else {
-    if (bufOut != NULL && outLen != 0) {
+    if (outLen > 0) {
       (*env)->SetByteArrayRegion(env, out, outOfs, outLen, (jbyte *)bufOut);
-      free(bufOut);
     }
-    free(context);
-    return outLen;
+    rc = outLen;
   }
+  free(context);
+  if (bufOut != (unsigned char *)(&outLen)) {
+    free(bufOut);
+  }
+  return rc;
 }
 
-
 /*
  * Class:     com_oracle_security_ucrypto_NativeKey
  * Method:    nativeFree