diff --git a/src/another_memcheck.cc b/src/another_memcheck.cc index c68a0e0..8cf0b17 100644 --- a/src/another_memcheck.cc +++ b/src/another_memcheck.cc @@ -8,6 +8,9 @@ // Local includes. #include "another_memcheck.h" +// Function declaration. +void exit_handler_stats(); + namespace SC_AM_Internal { Stats *stats = nullptr; int is_env_status = 0; @@ -95,11 +98,7 @@ namespace SC_AM_Internal { void *unused = new(recursive_mutex) std::recursive_mutex{}; (void)unused; - on_exit([] ([[maybe_unused]] int status, void *ptr) { - Stats *stats = reinterpret_cast(ptr); - stats->print_status(); - stats->cleanup(); - }, this); + std::atexit(exit_handler_stats); } void Stats::cleanup() { @@ -218,4 +217,13 @@ namespace SC_AM_Internal { } } +// Function definition. +void exit_handler_stats() { + if (SC_AM_Internal::stats != nullptr) { + SC_AM_Internal::stats->print_status(); + SC_AM_Internal::stats->cleanup(); + SC_AM_Internal::stats = nullptr; + } +} + // vim: et sw=2 ts=2 sts=2