From 04212c3d55cdf59324e05b19646d1a8fd753c9e1 Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Tue, 31 Aug 2021 11:54:42 +0100 Subject: [PATCH] added double free detection --- src/util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 7181ffc..c60f17e 100644 --- a/src/util.c +++ b/src/util.c @@ -133,15 +133,19 @@ void *CALLOC(size_t nmemb, size_t size) { void *ptr = calloc(nmemb, size); if (!ptr) { - lprintf(fatal, "calloc() failed, %s!\n", strerror(errno)); + lprintf(fatal, "%s!\n", strerror(errno)); } return ptr; } void FREE(void *ptr) { - free(ptr); - ptr = NULL; + if (ptr) { + free(ptr); + ptr = NULL; + } else { + lprintf(fatal, "attempted to double free a pointer!\n"); + } } char *str_to_hex(char *s)