Some more memory leak fixes.

- delete SIM object
- delete i/o port to handler tables
- free plugin tables for enum parameters
This commit is contained in:
Volker Ruppert 2023-11-26 15:44:38 +01:00
parent ae107f2cb8
commit b319a6cb5d
7 changed files with 32 additions and 13 deletions

View File

@ -1871,6 +1871,15 @@ void bx_reset_options()
#endif
}
void bx_cleanup_options()
{
free(config_interface_list);
free(display_library_list);
free(vga_extension_names);
free(vga_extension_plugins);
free(pcislot_dev_list);
}
int bx_read_configuration(const char *rcfile)
{
// parse rcfile first, then parse arguments in order.

View File

@ -358,7 +358,7 @@ void bx_init_siminterface()
}
}
void bx_cleanup_siminterface()
int bx_cleanup_siminterface()
{
if (siminterface_log) {
delete siminterface_log;
@ -370,6 +370,9 @@ void bx_cleanup_siminterface()
}
io->exit_log2();
delete io;
int exit_code = SIM->get_exit_code();
delete SIM;
return exit_code;
}
bx_real_sim_c::bx_real_sim_c()

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001-2021 The Bochs Project
// Copyright (C) 2001-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
@ -770,7 +770,7 @@ public:
BOCHSAPI extern bx_simulator_interface_c *SIM;
extern void bx_init_siminterface();
extern void bx_cleanup_siminterface();
extern int bx_cleanup_siminterface();
#if defined(__WXMSW__) || defined(WIN32)
// Just to provide HINSTANCE, etc. in files that have not included bochs.h.

View File

@ -128,11 +128,6 @@ void bx_devices_c::init(BX_MEM_C *newmem)
io_write_handlers.next = &io_write_handlers;
io_write_handlers.prev = &io_write_handlers;
io_write_handlers.usage_count = 0; // not used with the default handler
if (read_port_to_handler)
delete [] read_port_to_handler;
if (write_port_to_handler)
delete [] write_port_to_handler;
read_port_to_handler = new struct io_handler_struct *[PORTS];
write_port_to_handler = new struct io_handler_struct *[PORTS];
@ -445,6 +440,11 @@ void bx_devices_c::exit()
// delete default write handler name
delete [] io_write_handlers.handler_name;
io_write_handlers.handler_name = NULL;
// delete port-to-handler tables
if (read_port_to_handler)
delete [] read_port_to_handler;
if (write_port_to_handler)
delete [] write_port_to_handler;
// delete IRQ handler names
for (int i = 0; i < BX_MAX_IRQS; i++) {
delete [] irq_handler_name[i];

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2021 The Bochs Project
// Copyright (C) 2011-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
@ -45,6 +45,11 @@ bx_soundmod_ctl_c::bx_soundmod_ctl_c()
put("soundctl", "SNDCTL");
}
bx_soundmod_ctl_c::~bx_soundmod_ctl_c()
{
free(sound_driver_names);
}
void bx_soundmod_ctl_c::init()
{
Bit8u i, count = 0;

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2021 The Bochs Project
// Copyright (C) 2011-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
@ -29,7 +29,7 @@ class bx_soundlow_midiout_c;
class BOCHSAPI bx_soundmod_ctl_c : public logfunctions {
public:
bx_soundmod_ctl_c();
~bx_soundmod_ctl_c() {}
~bx_soundmod_ctl_c();
void init(void);
void exit(void);
const char **get_driver_names();

View File

@ -68,6 +68,7 @@ int bx_init_main(int argc, char *argv[]);
void bx_init_hardware(void);
void bx_plugin_ctrl_reset(bool init_done);
void bx_init_options(void);
void bx_cleanup_options(void);
void bx_init_bx_dbg(void);
static const char *divider = "========================================================================";
@ -352,8 +353,9 @@ int bxmain(void)
#endif
plugin_cleanup();
BX_INSTR_EXIT_ENV();
bx_cleanup_siminterface();
return SIM->get_exit_code();
int exit_code = bx_cleanup_siminterface();
bx_cleanup_options();
return exit_code;
}
#if defined(__WXMSW__)