From ae107f2cb8011f9543b54957d90006837b02e2eb Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Sun, 26 Nov 2023 13:41:19 +0100 Subject: [PATCH] Some more memory leak fixes. - added method for logfunctions cleanup on app exit - delete default i/o handler names - delete pluginlog --- bochs/gui/siminterface.cc | 2 ++ bochs/iodev/devices.cc | 7 +++++++ bochs/logio.cc | 10 +++++++++- bochs/logio.h | 3 ++- bochs/plugin.cc | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index 0ffa1f79f..4f183dfb1 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -368,6 +368,8 @@ void bx_cleanup_siminterface() delete root_param; root_param = NULL; } + io->exit_log2(); + delete io; } bx_real_sim_c::bx_real_sim_c() diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index 8af9b76af..17c2de633 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -430,6 +430,9 @@ void bx_devices_c::exit() delete [] curr->handler_name; delete curr; } + // delete default read handler name + delete [] io_read_handlers.handler_name; + io_read_handlers.handler_name = NULL; struct io_handler_struct *io_write_handler = io_write_handlers.next; while (io_write_handler != &io_write_handlers) { io_write_handler->prev->next = io_write_handler->next; @@ -439,6 +442,10 @@ void bx_devices_c::exit() delete [] curr->handler_name; delete curr; } + // delete default write handler name + delete [] io_write_handlers.handler_name; + io_write_handlers.handler_name = NULL; + // delete IRQ handler names for (int i = 0; i < BX_MAX_IRQS; i++) { delete [] irq_handler_name[i]; irq_handler_name[i] = NULL; diff --git a/bochs/logio.cc b/bochs/logio.cc index a3ddf6732..1b3fc5f4b 100644 --- a/bochs/logio.cc +++ b/bochs/logio.cc @@ -2,7 +2,7 @@ // $Id$ ///////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2001-2020 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 @@ -171,6 +171,7 @@ void iofunctions::init_log(int fd) init_log(tmpfd); }; +// called at simulation exit void iofunctions::exit_log() { flush(); @@ -182,6 +183,13 @@ void iofunctions::exit_log() } } +// called at application exit +void iofunctions::exit_log2() +{ + delete log; + delete genlog; +} + // all other functions may use genlog safely. #define LOG_THIS genlog-> diff --git a/bochs/logio.h b/bochs/logio.h index 5c473122b..b1eff5134 100644 --- a/bochs/logio.h +++ b/bochs/logio.h @@ -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 @@ -112,6 +112,7 @@ public: void init_log(int fd); void init_log(FILE *fs); void exit_log(); + void exit_log2(); void set_log_prefix(const char *prefix); int get_n_logfns() const { return n_logfn; } logfunc_t *get_logfn(int index) { return logfn_list[index]; } diff --git a/bochs/plugin.cc b/bochs/plugin.cc index 5cb97eb4f..bc12d5135 100644 --- a/bochs/plugin.cc +++ b/bochs/plugin.cc @@ -670,6 +670,7 @@ void plugin_cleanup(void) #else plugin_cleanup_np(); #endif + delete pluginlog; }