From 3b44724ac9924e3cc76cdc3d6843852423302d9e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 14 Nov 2024 12:25:07 +0900 Subject: [PATCH] Add stat counts for bad `realloc`s and `free`s --- src/another_memcheck.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/another_memcheck.cc b/src/another_memcheck.cc index 50204cf..9fceb7f 100644 --- a/src/another_memcheck.cc +++ b/src/another_memcheck.cc @@ -16,6 +16,8 @@ namespace SC_AM_Internal { int is_env_status = 0; unsigned long long Malloced::count = 0; unsigned long long null_count = 0; + unsigned long long bad_realloc_count = 0; + unsigned long long bad_free_count = 0; Stats *get_init_stats() { Stats *stats = reinterpret_cast( @@ -148,7 +150,8 @@ namespace SC_AM_Internal { if (ptr) { if (!ListNode::remove_from_list(malloced_list_head, ptr, this)) { - std::clog << "WARNING: Attempted free of unknown memory location!\n"; + std::clog << "WARNING: Attempted realloc of unknown memory location!\n"; + ++bad_realloc_count; } } @@ -186,6 +189,7 @@ namespace SC_AM_Internal { if (ptr) { if (!ListNode::remove_from_list(malloced_list_head, ptr)) { std::clog << "\nWARNING: Attempted free of unknown memory location!"; + ++bad_free_count; } else { result = true; real_free(ptr); @@ -215,6 +219,8 @@ namespace SC_AM_Internal { } } std::clog << "Attempted to free a NULL ptr " << null_count << " times.\n"; + std::clog << "Attempted to realloc an invalid ptr " << bad_realloc_count << " times.\n"; + std::clog << "Attempted to free an invalid ptr " << bad_free_count << " times.\n"; } }