no memory leak

This commit is contained in:
Anton Samokhvalov 2021-12-29 15:23:37 +03:00
parent 35dccb1038
commit fe66d52a38
2 changed files with 10 additions and 7 deletions

View file

@ -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));
const auto excode = (sig != -1 ? sig : 0);
close(0);
//? Assume error if still not cleaned up and call quick_exit to avoid a segfault from Tools::atomic_lock destructor
#ifndef __APPLE__
quick_exit(excode);
if (Tools::active_locks > 0) {
quick_exit((sig != -1 ? sig : 0));
}
#endif
exit(excode);
if (sig != -1) exit(sig);
}
//* Handler for SIGTSTP; stops threads, restores terminal and sends SIGSTOP

View file

@ -82,10 +82,14 @@ namespace Input {
struct InputThr {
InputThr() : thr(run, this) {
thr.detach();
}
static void run(InputThr* that) {
that->runImpl();
try {
that->runImpl();
} catch (...) {}
delete that;
}
void runImpl() {
@ -120,7 +124,6 @@ namespace Input {
}
static InputThr& instance() {
// intentional memory leak, to simplify shutdown process
static InputThr* input = new InputThr();
return *input;