diff options
Diffstat (limited to 'src/common/mm.c')
-rw-r--r-- | src/common/mm.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/common/mm.c b/src/common/mm.c index b461241..e047bf9 100644 --- a/src/common/mm.c +++ b/src/common/mm.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <mcheck.h> #include <errno.h> #include <unistd.h> #include <execinfo.h> @@ -522,6 +523,10 @@ static int __passthru_memalign(void **ptr, size_t align, size_t size, return posix_memalign(ptr, align, size); } +MRP_INIT static void menory_check_init() +{ + mcheck(NULL); +} static void __passthru_free(void *ptr, const char *file, int line, const char *func) @@ -529,8 +534,14 @@ static void __passthru_free(void *ptr, const char *file, int line, MRP_UNUSED(file); MRP_UNUSED(line); MRP_UNUSED(func); + if (ptr == NULL) + return; - free(ptr); + if (mprobe(ptr) == MCHECK_OK) + free(ptr); + else { + mrp_log_error("Invalid pointer passed to fuction free"); + } } @@ -579,7 +590,8 @@ int mrp_mm_memalign(void **ptr, size_t align, size_t size, const char *file, void mrp_mm_free(void *ptr, const char *file, int line, const char *func) { - return __mm.free(ptr, file, line, func); + __mm.free(ptr, file, line, func); + return; } |