Make test_realloc not leak in failure case.

This commit is contained in:
Matthew Parkinson
2019-08-11 07:44:36 +01:00
parent a32882cd55
commit 6151b7a9b2

View File

@@ -48,8 +48,11 @@ void test_realloc(void* p, size_t size, int err, bool null)
{
fprintf(stderr, "realloc(%p(%d), %d)\n", p, int(size), (int)size);
errno = 0;
p = our_realloc(p, size);
check_result(size, 1, p, err, null);
auto new_p = our_realloc(p, size);
// Realloc failure case, deallocate original block
if (new_p == nullptr && size != 0)
our_free(p);
check_result(size, 1, new_p, err, null);
}
void test_posix_memalign(size_t size, size_t align, int err, bool null)