From d93ba6ef1dffada47acae6d8a4ea0bda70ddaba0 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Mon, 24 Oct 2016 14:51:16 +0200 Subject: [PATCH] 8168542: os::realloc should return a valid pointer for input size=0 Reviewed-by: dholmes, cjplummer, dsamersoff, rehn --- hotspot/src/share/vm/runtime/os.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hotspot/src/share/vm/runtime/os.cpp b/hotspot/src/share/vm/runtime/os.cpp index 47a7b5672a4..b48edb441fb 100644 --- a/hotspot/src/share/vm/runtime/os.cpp +++ b/hotspot/src/share/vm/runtime/os.cpp @@ -649,6 +649,12 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa return NULL; } + if (size == 0) { + // return a valid pointer if size is zero + // if NULL is returned the calling functions assume out of memory. + size = 1; + } + #ifndef ASSERT NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); @@ -669,9 +675,6 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa // NMT support void* membase = MemTracker::malloc_base(memblock); verify_memory(membase); - if (size == 0) { - return NULL; - } // always move the block void* ptr = os::malloc(size, memflags, stack); if (PrintMalloc && tty != NULL) {