RFR: JDK-8264111 (fs) Leaking NativeBuffers in case of errors during UnixUserDefinedFileAttributeView.read/write
Alan Bateman
alanb at openjdk.java.net
Thu Mar 25 11:40:39 UTC 2021
On Wed, 24 Mar 2021 10:37:56 GMT, Sebastian Stenzel <github.com+1204330+overheadhunter at openjdk.org> wrote:
> Added new private methods for `read(String name, long address, int rem)` and `write(String name, long address, int rem)` that take an address as an argument and thereby no longer need to deal with any NativeBuffers.
>
> This allows a certain simplification of `read(String name, ByteBuffer dst)` and `write(String name, ByteBuffer src)` and use of `try (NativeBuffer nb = NativeBuffers.getNativeBuffer(rem)) {...}` which fixes the issue.
This looks good.
Would you mind adding "@Override" to the public write method so it is consistent with the other public methods.
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); }
-------------
PR: https://git.openjdk.java.net/jdk/pull/3171
More information about the nio-dev
mailing list