Add checks/output-stats for NULL-ptr frees

This commit is contained in:
Stephen Seo 2024-11-12 20:02:47 +09:00
parent 14301c372d
commit a6f716c8a2

View file

@ -15,6 +15,7 @@ namespace SC_AM_Internal {
Stats *stats = nullptr; Stats *stats = nullptr;
int is_env_status = 0; int is_env_status = 0;
unsigned long long Malloced::count = 0; unsigned long long Malloced::count = 0;
unsigned long long null_count = 0;
Stats *get_init_stats() { Stats *get_init_stats() {
Stats *stats = reinterpret_cast<SC_AM_Internal::Stats*>( Stats *stats = reinterpret_cast<SC_AM_Internal::Stats*>(
@ -184,11 +185,14 @@ namespace SC_AM_Internal {
if (ptr) { if (ptr) {
if (!ListNode::remove_from_list(malloced_list_head, 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 { } else {
result = true; result = true;
real_free(ptr); real_free(ptr);
} }
} else {
std::clog << "\nWARNING: Attempted to free a NULL ptr!";
++null_count;
} }
((std::recursive_mutex*)recursive_mutex)->unlock(); ((std::recursive_mutex*)recursive_mutex)->unlock();
@ -210,6 +214,7 @@ namespace SC_AM_Internal {
<< " id " << node->data->id << '\n'; << " id " << node->data->id << '\n';
} }
} }
std::clog << "Attempted to free a NULL ptr " << null_count << " times.\n";
} }
} }