From c1f540e61e5294a151dd6591a7533374fd2abce5 Mon Sep 17 00:00:00 2001 From: Anton Samokhvalov Date: Wed, 29 Dec 2021 15:46:15 +0300 Subject: [PATCH] Revert "no memory leak" This reverts commit fe66d52a38bbc65703482db4fcfca7300d6953d9. --- src/btop.cpp | 10 +++++----- src/btop_input.cpp | 7 ++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/btop.cpp b/src/btop.cpp index 48884ba..ac49a7e 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -237,15 +237,15 @@ void clean_quit(int sig) { std::cerr << Global::fg_red << "ERROR: " << Global::fg_white << Global::exit_error_msg << Fx::reset << endl; } Logger::info("Quitting! Runtime: " + sec_to_dhms(time_s() - Global::start_time)); - close(0); + + const auto excode = (sig != -1 ? sig : 0); + //? Assume error if still not cleaned up and call quick_exit to avoid a segfault from Tools::atomic_lock destructor #ifndef __APPLE__ - if (Tools::active_locks > 0) { - quick_exit((sig != -1 ? sig : 0)); - } + quick_exit(excode); #endif - if (sig != -1) exit(sig); + exit(excode); } //* Handler for SIGTSTP; stops threads, restores terminal and sends SIGSTOP diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 7a8d910..85ba644 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -82,14 +82,10 @@ namespace Input { struct InputThr { InputThr() : thr(run, this) { - thr.detach(); } static void run(InputThr* that) { - try { - that->runImpl(); - } catch (...) {} - delete that; + that->runImpl(); } void runImpl() { @@ -124,6 +120,7 @@ namespace Input { } static InputThr& instance() { + // intentional memory leak, to simplify shutdown process static InputThr* input = new InputThr(); return *input;