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: 850a75c182 ("fix compilation with GCC12")

Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
Nick Hainke 2022-06-13 20:35:57 +02:00
parent 5d8df44a3a
commit 58861a1adb

View file

@ -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);