RFR: 8294717: (bf) DirectByteBuffer constructor will leak if allocating Deallocator or Cleaner fails with OOME

Alan Bateman alanb at openjdk.org
Thu Oct 6 09:02:22 UTC 2022


On Wed, 5 Oct 2022 23:54:47 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Catch any `Throwable` from the `Deallocator` constructor or `Cleaner::create` and free memory to prevent a leak.

src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template line 148:

> 146:         } catch (Throwable t) {
> 147:             // Prevent leak if the Deallocator or Cleaner fail for any reason
> 148:             UNSAFE.freeMemory(base);

Bits.unreserveMemory is also needed here.

-------------

PR: https://git.openjdk.org/jdk/pull/10588


More information about the nio-dev mailing list