changeset 14382:60795927342a

8155211: Ucrypto Library leaks native memory Summary: Free the memory allocated by calloc(0, x) calls Reviewed-by: valeriep, igerasim
author stuefe
date Sat, 07 May 2016 00:26:02 +0000
parents b9ed1a4feefb
children 4aa52dc73711
files src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c
diffstat 1 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c	Fri May 06 14:03:08 2016 -0700
+++ b/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);
+    rc = -rv;
+  } else {
+    if (outLen > 0) {
+      (*env)->SetByteArrayRegion(env, out, outOfs, outLen, (jbyte *)bufOut);
     }
-    return -rv;
-  } else {
-    if (bufOut != NULL && 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