From 293b18e4bf1d3bf8a72ccf2ca688b89f7e72e7c3 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 12 Nov 2024 16:32:23 +0900 Subject: [PATCH] Avoid segfault on `exit(...)` Avoids segfault by not freeing the internal structure handling memory allocations. When the process ends, the OS should reclaim all memory, even if it isn't free'd during process execution. --- src/another_memcheck.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/another_memcheck.cc b/src/another_memcheck.cc index f2b4621..761342a 100644 --- a/src/another_memcheck.cc +++ b/src/another_memcheck.cc @@ -217,9 +217,12 @@ namespace SC_AM_Internal { void exit_handler_stats() { if (SC_AM_Internal::stats != nullptr) { SC_AM_Internal::stats->print_status(); - using SCS_AM_INTERNAL_Stats = SC_AM_Internal::Stats; - SC_AM_Internal::stats->~SCS_AM_INTERNAL_Stats(); - SC_AM_Internal::stats = nullptr; + + // Avoids segfault when program calls `exit(...)`. OS should reclaim memory + // when the process ends even if it isn't free'd here. + //using SCS_AM_INTERNAL_Stats = SC_AM_Internal::Stats; + //SC_AM_Internal::stats->~SCS_AM_INTERNAL_Stats(); + //SC_AM_Internal::stats = nullptr; } }