Skip to content

Commit

Permalink
8294717: (bf) DirectByteBuffer constructor will leak if allocating De…
Browse files Browse the repository at this point in the history
…allocator or Cleaner fails with OOME

Reviewed-by: alanb
  • Loading branch information
Brian Burkhalter committed Oct 7, 2022
1 parent c1166a3 commit 4cbac40
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -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);
Expand Down

1 comment on commit 4cbac40

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.