From 6151b7a9b23d8d9b7c7e8eaabcfca64f82512801 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Sun, 11 Aug 2019 07:44:36 +0100 Subject: [PATCH] Make test_realloc not leak in failure case. --- src/test/func/malloc/malloc.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index 8974e3a..b3dd268 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -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)