Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.


8263558: Possible NULL dereference in fast path arena free if ZapReso…
Browse files Browse the repository at this point in the history
…urceArea is true

Backport-of: d2c137d408b9c44f8f8d71e62dfea24a4279300e
  • Loading branch information
Harold Seigel committed Apr 6, 2021
1 parent 27c8449 commit 426cb6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hotspot/share/memory/arena.cpp
Expand Up @@ -373,7 +373,14 @@ void* Arena::grow(size_t x, AllocFailType alloc_failmode) {

// Reallocate storage in Arena.
void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {
if (new_size == 0) return NULL;
if (new_size == 0) {
Afree(old_ptr, old_size); // like realloc(3)
return NULL;
if (old_ptr == NULL) {
assert(old_size == 0, "sanity");
return Amalloc(new_size, alloc_failmode); // as with realloc(3), a NULL old ptr is equivalent to malloc(3)
#ifdef ASSERT
if (UseMallocOnly) {
// always allocate a new object (otherwise we'll free this one twice)
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/memory/arena.hpp
Expand Up @@ -186,6 +186,9 @@ class Arena : public CHeapObj<mtNone> {

// Fast delete in area. Common case is: NOP (except for storage reclaimed)
bool Afree(void *ptr, size_t size) {
if (ptr == NULL) {
return true; // as with free(3), freeing NULL is a noop.
#ifdef ASSERT
if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
if (UseMallocOnly) return true;
Expand Down

1 comment on commit 426cb6a

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.