]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
test-skeleton.c (xrealloc): Support realloc-as-free
authorFlorian Weimer <fweimer@redhat.com>
Thu, 23 Jun 2016 12:17:57 +0000 (14:17 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 23 Jun 2016 14:12:48 +0000 (16:12 +0200)
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).

ChangeLog
test-skeleton.c

index 5f9edb42eb57f5a7ba6ca9bbf0e717a604a3775d..4bfee947a30d326e65d200e8756aaec09382600a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-06-23  Florian Weimer  <fweimer@redhat.com>
+
+       * test-skeleton.c (xrealloc): Support deallocation with n == 0.
+
 2016-06-23  Florian Weimer  <fweimer@redhat.com>
 
        * test-skeleton.c (xmalloc, xcalloc, xrealloc): Mark as
index 0be4af1daf0c537134e050380ae625e6b5dbfc71..d9bf989fa8381641912ba37401f09be2a51bbc57 100644 (file)
@@ -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