]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
memory: use free() instead of realloc() for size 0
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 5 Jun 2023 13:40:22 +0000 (15:40 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 8 Jun 2023 12:31:52 +0000 (14:31 +0200)
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

index 03366e509f29cf4ec3d76aeba4d5fa45109ca3f1..25a484def9f23af4bc58558fdfed9535aaa5f194 100644 (file)
--- 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;