Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8264111

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 17
    • None
    • 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.

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

              Created:
              Updated:
              Resolved: