Skip to content

Commit 109970f

Browse files
committed
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.
1 parent ca10b9e commit 109970f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

memory.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ Realloc(void *ptr, size_t size)
4747
{
4848
void *r;
4949

50+
if (size == 0) {
51+
Free(ptr);
52+
return NULL;
53+
}
54+
5055
r = realloc(ptr, size);
51-
if (!r && size)
56+
if (!r)
5257
LOG_FATAL("Could not allocate memory");
5358

5459
return r;

0 commit comments

Comments
 (0)