From 081d5e77112517eda85dab058d5a6dc44e562de8 Mon Sep 17 00:00:00 2001 From: Shwartsman Date: Fri, 24 Nov 2023 20:25:05 +0200 Subject: [PATCH] address most of the memory leaks the param tree, siminterface log and SIM were not released handle all but SIM for now should reduce the memory leaks list dramatically --- bochs/gui/siminterface.cc | 22 +++++++++++++++++----- bochs/gui/siminterface.h | 1 + bochs/main.cc | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index 09594c2b3..a214522a8 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -345,15 +345,27 @@ bx_param_enum_c *bx_real_sim_c::get_param_enum(const char *pname, bx_param_c *ba void bx_init_siminterface() { if (SIM == NULL) { + SIM = new bx_real_sim_c(); + } + if (siminterface_log == NULL) { siminterface_log = new logfunctions(); siminterface_log->put("siminterface", "SIM"); - SIM = new bx_real_sim_c(); } if (root_param == NULL) { root_param = new bx_list_c(NULL, "bochs", - "list of top level bochs parameters" - ); + "list of top level bochs parameters"); + } +} + +void bx_cleanup_siminterface() +{ + if (siminterface_log) { + delete siminterface_log; + } + if (root_param) { + root_param->clear(); + root_param = NULL; } } @@ -1073,9 +1085,9 @@ void bx_real_sim_c::init_statistics() void bx_real_sim_c::cleanup_statistics() { - bx_list_c *list; + bx_list_c *list = get_statistics_root(); - if ((list = get_statistics_root()) != NULL) { + if (list != NULL) { list->clear(); } } diff --git a/bochs/gui/siminterface.h b/bochs/gui/siminterface.h index 940499041..d7eed74d9 100644 --- a/bochs/gui/siminterface.h +++ b/bochs/gui/siminterface.h @@ -770,6 +770,7 @@ public: BOCHSAPI extern bx_simulator_interface_c *SIM; extern void bx_init_siminterface(); +extern void bx_cleanup_siminterface(); #if defined(__WXMSW__) || defined(WIN32) // Just to provide HINSTANCE, etc. in files that have not included bochs.h. diff --git a/bochs/main.cc b/bochs/main.cc index 1c7d30f2d..9d34c0e12 100644 --- a/bochs/main.cc +++ b/bochs/main.cc @@ -352,6 +352,7 @@ int bxmain(void) #endif plugin_cleanup(); BX_INSTR_EXIT_ENV(); + bx_cleanup_siminterface(); return SIM->get_exit_code(); }