From 1b85074c81b11066f60b6f4d8c827788429000a2 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Thu, 3 Apr 2014 02:44:41 -0700 Subject: [PATCH] Rearrange suspicious pointer logging --- src/ChangeLog | 6 ++++++ src/alloc.c | 34 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a628148bbd..b2a8f81f3a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-04-03 Daniel Colascione + + * alloc.c (detect_suspicious_free): Split actual stack capturing + out into new function for easier breakpoint setting. + (note_suspicious_free): New function. + 2014-04-03 Daniel Colascione In all places below, change expressions of the form sizeof(arr) / diff --git a/src/alloc.c b/src/alloc.c index 46b4f5021d..7c63fa05ac 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6845,28 +6845,34 @@ find_suspicious_object_in_range (void* begin, void* end) } static void -detect_suspicious_free (void* ptr) +note_suspicious_free (void* ptr) { - int i; struct suspicious_free_record* rec; + rec = &suspicious_free_history[suspicious_free_history_index++]; + if (suspicious_free_history_index == + EARRAYSIZE (suspicious_free_history)) + { + suspicious_free_history_index = 0; + } + + memset (rec, 0, sizeof (*rec)); + rec->suspicious_object = ptr; +#ifdef HAVE_EXECINFO_H + backtrace (&rec->backtrace[0], EARRAYSIZE (rec->backtrace)); +#endif +} + +static void +detect_suspicious_free (void* ptr) +{ + int i; eassert (ptr != NULL); for (i = 0; i < EARRAYSIZE (suspicious_objects); ++i) if (suspicious_objects[i] == ptr) { - rec = &suspicious_free_history[suspicious_free_history_index++]; - if (suspicious_free_history_index == - EARRAYSIZE (suspicious_free_history)) - { - suspicious_free_history_index = 0; - } - - memset (rec, 0, sizeof (*rec)); - rec->suspicious_object = ptr; -#ifdef HAVE_EXECINFO_H - backtrace (&rec->backtrace[0], EARRAYSIZE (rec->backtrace)); -#endif + note_suspicious_free (ptr); suspicious_objects[i] = NULL; } } -- 2.39.2