< prev index next >
src/share/vm/runtime/os.cpp
Print this page
rev 12652 : 8168542: os::realloc should return a valid pointer for input size=0
Reviewed-by: dholmes, cjplummer, dsamersoff, rehn
*** 647,656 ****
--- 647,662 ----
// For the test flag -XX:MallocMaxTestWords
if (has_reached_max_malloc_test_peak(size)) {
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));
// NMT support
void* membase = MemTracker::record_free(memblock);
*** 667,679 ****
breakpoint();
}
// 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) {
tty->print_cr("os::realloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, p2i(memblock), p2i(ptr));
}
--- 673,682 ----
< prev index next >