From 34eb9ff6708c28d0fd5b314f81736e8091335a13 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Thu, 25 May 2023 18:26:17 +0000 Subject: [PATCH] Report memory hook issues as errors, segfault on error. --- src/Main.c | 2 ++ src/Telodendria.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Main.c b/src/Main.c index 2c0c249..6afa340 100644 --- a/src/Main.c +++ b/src/Main.c @@ -572,6 +572,8 @@ finish: Log(LOG_DEBUG, "Freed HTTP server %lu.", i); } ArrayFree(httpServers); + httpServers = NULL; + Log(LOG_DEBUG, "Freed HTTP servers array."); } diff --git a/src/Telodendria.c b/src/Telodendria.c index 5e801be..39c18a8 100644 --- a/src/Telodendria.c +++ b/src/Telodendria.c @@ -72,7 +72,7 @@ void TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) { char *action; - int warn = 0; + int err = 0; if (!args && ((a == MEMORY_ALLOCATE) || (a == MEMORY_REALLOCATE) || (a == MEMORY_FREE))) { @@ -91,11 +91,11 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) action = "Freed"; break; case MEMORY_BAD_POINTER: - warn = 1; + err = 1; action = "Bad pointer to"; break; case MEMORY_CORRUPTED: - warn = 1; + err = 1; action = "Corrupted block of"; break; default: @@ -103,13 +103,13 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) break; } - Log(warn ? LOG_WARNING : LOG_DEBUG, + Log(err ? LOG_ERR : LOG_DEBUG, "%s:%d: %s %lu bytes of memory at %p.", MemoryInfoGetFile(i), MemoryInfoGetLine(i), action, MemoryInfoGetSize(i), MemoryInfoGetPointer(i)); - if (a == MEMORY_CORRUPTED) + if (err) { raise(SIGSEGV); }