From: Miroslav Lichvar Date: Mon, 5 Jun 2023 13:40:22 +0000 (+0200) Subject: memory: use free() instead of realloc() for size 0 X-Git-Tag: 4.4-pre2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=109970f687a5f2735c913e6f28c290a93a216439;p=thirdparty%2Fchrony.git memory: use free() instead of realloc() for size 0 valgrind 3.21.0 reports realloc() of 0 bytes as an error due to having different behavior on different systems. The only place where this can happen in chrony is the array, which doesn't care what value realloc() returns. Modify the realloc wrapper to call free() in this case to make valgrind happy. --- diff --git a/memory.c b/memory.c index 03366e50..25a484de 100644 --- a/memory.c +++ b/memory.c @@ -47,8 +47,13 @@ Realloc(void *ptr, size_t size) { void *r; + if (size == 0) { + Free(ptr); + return NULL; + } + r = realloc(ptr, size); - if (!r && size) + if (!r) LOG_FATAL("Could not allocate memory"); return r;