Skip to content

Commit d2c137d

Browse files
committed
8263558: Possible NULL dereference in fast path arena free if ZapResourceArea is true
Reviewed-by: kbarrett, coleenp
1 parent ab66d69 commit d2c137d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/hotspot/share/memory/arena.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,14 @@ void* Arena::grow(size_t x, AllocFailType alloc_failmode) {
367367

368368
// Reallocate storage in Arena.
369369
void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {
370-
if (new_size == 0) return NULL;
370+
if (new_size == 0) {
371+
Afree(old_ptr, old_size); // like realloc(3)
372+
return NULL;
373+
}
374+
if (old_ptr == NULL) {
375+
assert(old_size == 0, "sanity");
376+
return Amalloc(new_size, alloc_failmode); // as with realloc(3), a NULL old ptr is equivalent to malloc(3)
377+
}
371378
#ifdef ASSERT
372379
if (UseMallocOnly) {
373380
// always allocate a new object (otherwise we'll free this one twice)

src/hotspot/share/memory/arena.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ class Arena : public CHeapObj<mtNone> {
184184

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

0 commit comments

Comments
 (0)