RFR: JDK-8264111 (fs) Leaking NativeBuffers in case of errors during UnixUserDefinedFileAttributeView.read/write [v2]
Alan Bateman
alanb at openjdk.java.net
Fri Mar 26 07:15:33 UTC 2021
On Thu, 25 Mar 2021 11:53:01 GMT, Sebastian Stenzel <github.com+1204330+overheadhunter at openjdk.org> wrote:
>> src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java line 174:
>>
>>> 172: if (dst instanceof sun.nio.ch.DirectBuffer buf) {
>>> 173: long address = buf.address() + pos;
>>> 174: int n = read(name, address, rem);
>>
>> We need to add reachabilityFence here, don't mind if we do it now while changing this code or later.
>> That is, it should be try { n = read(name, address, rem); } finally { Reference.reachabilityFence(buf); }
>
> Never heard of this before, just read the docs the first time. Do I get this right, that this helps to protect against instant finalization of the buffer in e.g. `attrView.read("foo", ByteBuffer.allocateDirect(42))`?
>
> What about the `write` case?
Yes, everywhere where the direct memory is accessed (so read and write here). I don't mind if we do it as a separate issue or here, I only suggested it here because it's changed the new code in this patch.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3171
More information about the nio-dev
mailing list