Report memory hook issues as errors, segfault on error.

This commit is contained in:
Jordan Bancino 2023-05-25 18:26:17 +00:00
parent e87a0647e0
commit 34eb9ff670
2 changed files with 7 additions and 5 deletions

View file

@ -572,6 +572,8 @@ finish:
Log(LOG_DEBUG, "Freed HTTP server %lu.", i); Log(LOG_DEBUG, "Freed HTTP server %lu.", i);
} }
ArrayFree(httpServers); ArrayFree(httpServers);
httpServers = NULL;
Log(LOG_DEBUG, "Freed HTTP servers array."); Log(LOG_DEBUG, "Freed HTTP servers array.");
} }

View file

@ -72,7 +72,7 @@ void
TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args) TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
{ {
char *action; char *action;
int warn = 0; int err = 0;
if (!args && ((a == MEMORY_ALLOCATE) || (a == MEMORY_REALLOCATE) || (a == MEMORY_FREE))) if (!args && ((a == MEMORY_ALLOCATE) || (a == MEMORY_REALLOCATE) || (a == MEMORY_FREE)))
{ {
@ -91,11 +91,11 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
action = "Freed"; action = "Freed";
break; break;
case MEMORY_BAD_POINTER: case MEMORY_BAD_POINTER:
warn = 1; err = 1;
action = "Bad pointer to"; action = "Bad pointer to";
break; break;
case MEMORY_CORRUPTED: case MEMORY_CORRUPTED:
warn = 1; err = 1;
action = "Corrupted block of"; action = "Corrupted block of";
break; break;
default: default:
@ -103,13 +103,13 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
break; break;
} }
Log(warn ? LOG_WARNING : LOG_DEBUG, Log(err ? LOG_ERR : LOG_DEBUG,
"%s:%d: %s %lu bytes of memory at %p.", "%s:%d: %s %lu bytes of memory at %p.",
MemoryInfoGetFile(i), MemoryInfoGetLine(i), MemoryInfoGetFile(i), MemoryInfoGetLine(i),
action, MemoryInfoGetSize(i), action, MemoryInfoGetSize(i),
MemoryInfoGetPointer(i)); MemoryInfoGetPointer(i));
if (a == MEMORY_CORRUPTED) if (err)
{ {
raise(SIGSEGV); raise(SIGSEGV);
} }