From 64ba17317dc9343f0958755ad04af71ec3da637b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 23 Jun 2016 14:17:57 +0200 Subject: test-skeleton.c (xrealloc): Support realloc-as-free If the requested size is zero, realloc returns NULL, but the deallocation is still successful, unless the pointer is also NULL, when realloc behaves as malloc (0). --- test-skeleton.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test-skeleton.c') diff --git a/test-skeleton.c b/test-skeleton.c index 0be4af1daf..d9bf989fa8 100644 --- a/test-skeleton.c +++ b/test-skeleton.c @@ -109,10 +109,10 @@ __attribute__ ((unused)) static void * xrealloc (void *p, size_t n) { - p = realloc (p, n); - if (p == NULL) + void *result = realloc (p, n); + if (result == NULL && (n > 0 || p == NULL)) oom_error ("realloc", n); - return p; + return result; } /* Write a message to standard output. Can be used in signal -- cgit 1.4.1