From 4d3d6c916888244f7556cfd61508b1d57a01a546 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 12 Nov 2024 15:29:17 +0900 Subject: [PATCH] Use atexit() instead of onexit() --- src/another_memcheck.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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