Commit 5def6500 authored by Oran Agra's avatar Oran Agra
Browse files

Fix zrealloc to behave similarly to je_realloc when size is 0

According to C11, the behavior of realloc with size 0 is now deprecated.
it can either behave as free(ptr) and return NULL, or return a valid pointer.
but in zmalloc it can lead to zmalloc_oom_handler and panic.
and that can affect modules that use it.

It looks like both glibc allocator and jemalloc behave like so:
  realloc(malloc(32),0) returns NULL
  realloc(NULL,0) returns a valid pointer

This commit changes zmalloc to behave the same
parent ffde73c5
......@@ -147,6 +147,10 @@ void *zrealloc(void *ptr, size_t size) {
size_t oldsize;
void *newptr;
if (size == 0 && ptr!=NULL) {
zfree(ptr);
return NULL;
}
if (ptr == NULL) return zmalloc(size);
#ifdef HAVE_MALLOC_SIZE
oldsize = zmalloc_size(ptr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment