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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 17
    • core-libs
    • None
    • b16

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: