From 858ae5805f3bea303edfcec8156494be2fa3580d Mon Sep 17 00:00:00 2001 From: Stefan Seefeld Date: Mon, 5 Aug 2013 10:54:24 -0400 Subject: [PATCH] Fix typo and robustify free() implementation. Signed-off-by: Stefan Seefeld --- memleak-finder.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/memleak-finder.c b/memleak-finder.c index 2f8b996..d3755ff 100644 --- a/memleak-finder.c +++ b/memleak-finder.c @@ -160,7 +160,7 @@ void *static_calloc(size_t nmemb, size_t size) if (nmemb * size > sizeof(static_calloc_buf) - static_calloc_len) return NULL; prev_len = static_calloc_len; - static_calloc_len += nmemb + size; + static_calloc_len += nmemb * size; return &static_calloc_buf[prev_len]; } @@ -341,6 +341,15 @@ free(void *ptr) { const void *caller = __builtin_return_address(0); + /* Check whether the memory was allocated with + * static_calloc, in which case there is nothing + * to free. + */ + if ((char*)ptr >= static_calloc_buf && + (char*)ptr < static_calloc_buf + STATIC_CALLOC_LEN) { + return; + } + do_init(); if (thread_in_hook) { -- 1.8.3.1