--- old/src/share/classes/sun/security/ec/ECKeyPairGenerator.java 2014-05-27 12:59:26.544793000 -0700 +++ new/src/share/classes/sun/security/ec/ECKeyPairGenerator.java 2014-05-27 12:59:26.392796000 -0700 @@ -123,9 +123,10 @@ } random.nextBytes(seed); + long[] handles = null; try { - long[] handles = generateECKeyPair(keySize, encodedParams, seed); + handles = generateECKeyPair(keySize, encodedParams, seed); // The 'params' object supplied above is equivalent to the native // one so there is no need to fetch it. @@ -146,6 +147,12 @@ } catch (Exception e) { throw new ProviderException(e); + } finally { + if (handles != null) { + // handles[2] points to the data structure containing + // both the native public and private key. + releaseECKeyPairData(handles[2]); + } } } @@ -168,6 +175,12 @@ private static native long[] generateECKeyPair(int keySize, byte[] encodedParams, byte[] seed) throws GeneralSecurityException; + + /* + * Releases the native memory allocated by generateECKeyPair. + */ + private static native void releaseECKeyPairData(long privKeyHandle); + /* * Extracts the encoded key data using the supplied handle. */