Attempt to fix some memory leaks in the plugins and gui code (discussion #144).

- Added plugin_cleanup() code for the version with plugins disabled.
- Added PLUGIN_FINI code for the gui plugins (except wx) to delete bx_gui object.
This commit is contained in:
Volker Ruppert 2023-11-25 18:15:47 +01:00
parent f0bbf25b5d
commit 890a1be2f2
2 changed files with 23 additions and 1 deletions

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2021 The Bochs Project
// Copyright (C) 2002-2023 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -584,6 +584,9 @@ enum {
genlog->info("installing %s module as the Bochs GUI", #gui_name); \
theGui = new bx_##gui_name##_gui_c (); \
bx_gui = theGui; \
} else if (mode == PLUGIN_FINI) { \
delete theGui; \
bx_gui = NULL; \
} else if (mode == PLUGIN_PROBE) { \
return (int)PLUGTYPE_GUI; \
} \

View File

@ -648,6 +648,10 @@ void plugin_startup(void)
#endif
}
#if !BX_PLUGINS
void plugin_cleanup_np(void);
#endif
void plugin_cleanup(void)
{
#if BX_PLUGINS
@ -663,6 +667,8 @@ void plugin_cleanup(void)
plugins = plugins->next;
delete dead_plug;
}
#else
plugin_cleanup_np();
#endif
}
@ -1212,6 +1218,19 @@ int bx_unload_opt_plugin(const char *name, bool devflag)
return 0;
}
void plugin_cleanup_np(void)
{
int i = 0;
while (strcmp(bx_builtin_plugins[i].name, "NULL")) {
if (bx_builtin_plugins[i].initialized == 1) {
bx_builtin_plugins[i].plugin_entry(NULL, bx_builtin_plugins[i].loadtype, PLUGIN_FINI);
bx_builtin_plugins[i].loadtype = PLUGTYPE_NULL;
bx_builtin_plugins[i].initialized = 0;
}
i++;
}
}
#endif
}