Skip to content

Commit

Permalink
address most of the memory leaks (#149)
Browse files Browse the repository at this point in the history
the param tree, siminterface log and SIM were not released handle all
but SIM for now
should reduce the memory leaks list dramatically
  • Loading branch information
stlintel authored Nov 24, 2023
1 parent 7f04cfd commit 3cad5c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bochs/gui/siminterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions bochs/gui/siminterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ class BOCHSAPI bx_simulator_interface_c {
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.
Expand Down
1 change: 1 addition & 0 deletions bochs/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ int bxmain(void)
#endif
plugin_cleanup();
BX_INSTR_EXIT_ENV();
bx_cleanup_siminterface();
return SIM->get_exit_code();
}

Expand Down

0 comments on commit 3cad5c3

Please sign in to comment.