From 88c78b4a03dc642665cb4df3428ca93eb235bd1a Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Mon, 13 Jun 2022 20:35:57 +0200 Subject: [PATCH] memory_utils: fix reallocation Fixes errors in the form of: dawn: mem-audit: Releasing memory we hadn't registered (tcpsocket.c:142)... dawn: mem-audit: attempted to register memory already registered (M@tcpsocket.c:114)... Fixes: 850a75c18293 ("fix compilation with GCC12") Signed-off-by: Nick Hainke --- src/utils/memory_utils.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/memory_utils.c b/src/utils/memory_utils.c index 7903d4a..0afc307 100644 --- a/src/utils/memory_utils.c +++ b/src/utils/memory_utils.c @@ -33,7 +33,21 @@ void* ret = NULL; case DAWN_REALLOC: ret = realloc(ptr, size); if (ret != NULL) - dawn_memory_unregister(DAWN_REALLOC, file, line, ret); +/* +GCC v12 has a new Wuse-after-free error. We can not unregister +the memory before doing a reallocation. The call can fail, so +ptr is never freed. However, the warning can be ignored, since +ptr is only used in the unregister function as a reference to +remove it from our memory auditing. +*/ +#if (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wuse-after-free" + dawn_memory_unregister(DAWN_REALLOC, file, line, ptr); +#pragma GCC diagnostic pop +#else + dawn_memory_unregister(DAWN_REALLOC, file, line, ptr); +#endif break; case DAWN_CALLOC: ret = calloc(nmemb, size);