(fs) Leaking NativeBuffers in case of errors during UnixUserDefinedFileAttributeView.read/write

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 17
    • Affects Version/s: None
    • Component/s: core-libs
    • None
    • b16

      In both `UnixUserDefinedFileAttributeView.read(...)` as well as `UnixUserDefinedFileAttributeView.write(...)`, NativeBuffers get allocated before the file handle is opened. If opening the file fails for whatever reason, an exception is thrown _before_ entering the try-finally block that would close/release the buffer again:

      https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L187
      https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L258

      To fix these two edge cases, as well as to avoid future similar problems, we should use try-with-resource for all NativeBuffers within UnixUserDefinedFileAttributeView.

            Assignee:
            Sebastian Stenzel
            Reporter:
            Sebastian Stenzel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: