From 109970f687a5f2735c913e6f28c290a93a216439 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 5 Jun 2023 15:40:22 +0200 Subject: [PATCH] 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. --- memory.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 03366e5..25a484d 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;