Skip to content

Commit 56b891e

Browse files
committed
Merge branch 'jk/xrealloc-avoid-use-after-free'
It was possible for xrealloc() to send a non-NULL pointer that has been freed, which has been fixed. * jk/xrealloc-avoid-use-after-free: xrealloc: do not reuse pointer freed by zero-length realloc()
2 parents 2f1757e + 6479ea4 commit 56b891e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

wrapper.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,13 @@ void *xrealloc(void *ptr, size_t size)
117117
{
118118
void *ret;
119119

120+
if (!size) {
121+
free(ptr);
122+
return xmalloc(0);
123+
}
124+
120125
memory_limit_check(size, 0);
121126
ret = realloc(ptr, size);
122-
if (!ret && !size)
123-
ret = realloc(ptr, 1);
124127
if (!ret)
125128
die("Out of memory, realloc failed");
126129
return ret;

0 commit comments

Comments
 (0)