From e7e274b13a44a63023f22630ac282ee2e919ffb7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 12 Oct 2012 17:05:05 -0700 Subject: [PATCH] Fix realloc(3) when chk_malloc debugging is on. The tests for a NULL pointer and size 0 were the wrong way round. From Intel's patch 9cae4f2ffc4778ed82be04711d8775a84092d4e2. Change-Id: I118aff3358aa5f34126d74bfaa43f6e2f1a89055 --- libc/bionic/malloc_debug_check.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libc/bionic/malloc_debug_check.cpp b/libc/bionic/malloc_debug_check.cpp index 4190a1df6..5ad3486f3 100644 --- a/libc/bionic/malloc_debug_check.cpp +++ b/libc/bionic/malloc_debug_check.cpp @@ -406,14 +406,16 @@ extern "C" void chk_free(void *ptr) { extern "C" void *chk_realloc(void *ptr, size_t size) { // log_message("%s: %s\n", __FILE__, __FUNCTION__); + if (!ptr) { + return chk_malloc(size); + } + +#ifdef REALLOC_ZERO_BYTES_FREE if (!size) { chk_free(ptr); return NULL; } - - if (!ptr) { - return chk_malloc(size); - } +#endif hdr_t* hdr = meta(ptr);