Skip to content

Commit

Permalink
test-skeleton.c (xrealloc): Support realloc-as-free
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
fweimer-rh committed Jun 23, 2016
1 parent 9d52cb0 commit 64ba173
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test-skeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64ba173

Please sign in to comment.