< prev index next >

src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto/nativeCrypto.c

Print this page
rev 14307 : 8155211: Ucrypto Library leaks native memory
Reviewed-by:

@@ -648,10 +648,11 @@
    jbyteArray out, jint outOfs) {
   crypto_ctx_t *context;
   unsigned char *bufIn;
   unsigned char *bufOut;
   int outLen, rv = 0;
+  jint rc;
 
   context = (crypto_ctx_t *) contextID;
 
   // out is null when nativeFinal() is called solely for resource clean up
   if (out == NULL) {

@@ -666,26 +667,24 @@
       return 0;
     }
   }
   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);
+    }
+    rc = outLen;
     }
     free(context);
-    return outLen;
+  if (bufOut != (unsigned char *)(&outLen)) {
+    free(bufOut);
   }
+  return rc;
 }
 
-
 /*
  * Class:     com_oracle_security_ucrypto_NativeKey
  * Method:    nativeFree
  * Signature: (JI)V
  */
< prev index next >