From a6f716c8a2c2640c88131bcf9bc628f700993da7 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 12 Nov 2024 20:02:47 +0900 Subject: [PATCH] Add checks/output-stats for NULL-ptr frees --- src/another_memcheck.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/another_memcheck.cc b/src/another_memcheck.cc index 761342a..a0f5cd8 100644 --- a/src/another_memcheck.cc +++ b/src/another_memcheck.cc @@ -15,6 +15,7 @@ namespace SC_AM_Internal { Stats *stats = nullptr; int is_env_status = 0; unsigned long long Malloced::count = 0; + unsigned long long null_count = 0; Stats *get_init_stats() { Stats *stats = reinterpret_cast( @@ -184,11 +185,14 @@ namespace SC_AM_Internal { if (ptr) { if (!ListNode::remove_from_list(malloced_list_head, ptr)) { - std::clog << "WARNING: Attempted free of unknown memory location!\n"; + std::clog << "\nWARNING: Attempted free of unknown memory location!"; } else { result = true; real_free(ptr); } + } else { + std::clog << "\nWARNING: Attempted to free a NULL ptr!"; + ++null_count; } ((std::recursive_mutex*)recursive_mutex)->unlock(); @@ -210,6 +214,7 @@ namespace SC_AM_Internal { << " id " << node->data->id << '\n'; } } + std::clog << "Attempted to free a NULL ptr " << null_count << " times.\n"; } }