From 9a1895eaeaaa93f56d8e87c691324f5463f62aec Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 22 Mar 2014 13:11:51 +0200 Subject: [PATCH] Fix some memory leak complaints from Valgrind --- include/core/command.hpp | 1 + include/platform/wxwidgets/platform.hpp | 1 + src/core/command.cpp | 6 ++++++ src/core/inthread.cpp | 1 + src/library/gamepad.cpp | 6 ++++++ src/platform/wxwidgets/keyboard.cpp | 18 ++++++++++++++++++ src/platform/wxwidgets/main.cpp | 2 ++ src/platform/wxwidgets/mainwindow.cpp | 1 + src/util/lsnes-dumpavi.cpp | 1 + 9 files changed, 37 insertions(+) diff --git a/include/core/command.hpp b/include/core/command.hpp index d261bfe8..576e0d7a 100644 --- a/include/core/command.hpp +++ b/include/core/command.hpp @@ -9,5 +9,6 @@ extern command::group lsnes_cmd; void refresh_alias_binds(); +void kill_alias_binds(); #endif diff --git a/include/platform/wxwidgets/platform.hpp b/include/platform/wxwidgets/platform.hpp index 735c3f3a..77d49856 100644 --- a/include/platform/wxwidgets/platform.hpp +++ b/include/platform/wxwidgets/platform.hpp @@ -35,6 +35,7 @@ void boot_emulator(loaded_rom& rom, moviefile& movie, bool fscreen); void handle_wx_keyboard(wxKeyEvent& e, bool polarity); std::string map_keycode_to_key(int kcode); void initialize_wx_keyboard(); +void deinitialize_wx_keyboard(); void signal_program_exit(); void signal_resize_needed(); void _runuifun_async(void (*fn)(void*), void* arg); diff --git a/src/core/command.cpp b/src/core/command.cpp index 5aa4b45a..91c448f3 100644 --- a/src/core/command.cpp +++ b/src/core/command.cpp @@ -33,3 +33,9 @@ void refresh_alias_binds() alias_binds[i] = new keyboard::invbind(lsnes_mapper, i, "Aliasā€£" + i); } } + +void kill_alias_binds() +{ + for(auto i : alias_binds) delete i.second; + alias_binds.clear(); +} diff --git a/src/core/inthread.cpp b/src/core/inthread.cpp index 43c46be7..10b9e77a 100644 --- a/src/core/inthread.cpp +++ b/src/core/inthread.cpp @@ -1701,6 +1701,7 @@ void voicethread_task() void voicethread_kill() { int_task->kill(); + delete int_task; int_task = NULL; } diff --git a/src/library/gamepad.cpp b/src/library/gamepad.cpp index 4edcade7..b5a78ee4 100644 --- a/src/library/gamepad.cpp +++ b/src/library/gamepad.cpp @@ -84,6 +84,12 @@ pad::pad(const std::string& _xname, unsigned _jnum) pad::~pad() { + //Set _axes_hat entries that alias to NULL. + for(auto i = _axes_hat.begin(); i != _axes_hat.end(); i++) + for(auto j = i; j != _axes_hat.end(); j++) + if(i != j && i->second == j->second) + j->second = NULL; + for(auto i : _axes_hat) delete i.second; } void pad::set_online(bool status) diff --git a/src/platform/wxwidgets/keyboard.cpp b/src/platform/wxwidgets/keyboard.cpp index 2b48b3ca..32f11e53 100644 --- a/src/platform/wxwidgets/keyboard.cpp +++ b/src/platform/wxwidgets/keyboard.cpp @@ -363,3 +363,21 @@ void initialize_wx_keyboard() } done = true; } + +void deinitialize_wx_keyboard() +{ + modifier_map.clear(); + key_map.clear(); + keys_allocated.clear(); + keys_held.clear(); + modifier_entry* m = modifiers; + while(m->name) { + delete m->allocated; + m++; + } + key_entry* k = keys; + while(k->name) { + delete k->allocated; + k++; + } +} diff --git a/src/platform/wxwidgets/main.cpp b/src/platform/wxwidgets/main.cpp index 09fd254f..4bdf3fc7 100644 --- a/src/platform/wxwidgets/main.cpp +++ b/src/platform/wxwidgets/main.cpp @@ -530,6 +530,8 @@ int lsnes_app::OnExit() platform::quit(); cleanup_all_keys(); cleanup_keymapper(); + kill_alias_binds(); + deinitialize_wx_keyboard(); return 0; } diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index c7be8f2e..07e539b3 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -591,6 +591,7 @@ namespace messages << "FATAL: " << e.what() << std::endl; platform::fatal_error(); } + delete args; return NULL; } diff --git a/src/util/lsnes-dumpavi.cpp b/src/util/lsnes-dumpavi.cpp index 897fb526..25187b3e 100644 --- a/src/util/lsnes-dumpavi.cpp +++ b/src/util/lsnes-dumpavi.cpp @@ -379,6 +379,7 @@ int main(int argc, char** argv) information_dispatch::do_dump_end(); quit_lua(); movb.release_memory(); + kill_alias_binds(); cleanup_all_keys(); return 0; } -- 2.11.4.GIT