RFR: 8258077: Using -Xcheck:jni can lead to a double-free after JDK-8193234
David Holmes
dholmes at openjdk.java.net
Fri Dec 11 07:22:08 UTC 2020
On Fri, 11 Dec 2020 06:46:06 GMT, Mauro Lacy <github.com+11656534+maurolacy at openjdk.org> wrote:
>> Hi David,
>>
>> Thanks for the issue, I'll change the title to properly reference it.
>>
>> The point is that I couldn't find those memory leaks. At least in the openjdk code base, I couldn't find tests for that functionality, so, no memory leaks.
>>
>> And, in any case, if there are tests in another code base, they are leaking because they are incorrect (IMO). In that they are not always following the right calling pattern for `ReleasePrimitiveArrayCritical`.
>>
>> `ReleasePrimitiveArrayCritical`, despite its name (and to the best of our knowledge), does **not** release the buffer when called with `JNI_COMMIT`. So, it must be called again with a different release mode, to properly release the buffer.
>>
>> And this, independently of the JVM flags. Or, it will manifest inconsistent behaviour; which is what's happening.
>
> issue 8258077: Using -Xcheck:jni can lead to a double-free after JDK-8193234
There are no tests for this, this was about external users of JNI encountering the leak. I also just re-checked the JDK source and it seems this code also suffers from the COMMIT-only problem:
./jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_crypt.c
The debate is over what constitutes correct and incorrect usage here - as I just wrote in the bug report. I will see if there is a reasonable way to support both.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1697
More information about the hotspot-dev
mailing list