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

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2022-10-07 17:43:00 +00:00
parent c1166a304d
commit 4cbac40de9

@ -141,7 +141,14 @@ class Direct$Type$Buffer$RW$$BO$
} else {
address = base;
}
cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
try {
cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
} catch (Throwable t) {
// Prevent leak if the Deallocator or Cleaner fail for any reason
UNSAFE.freeMemory(base);
Bits.unreserveMemory(size, cap);
throw t;
}
att = null;
#else[rw]
super(cap);