From 924b3ac033df5ff5c0face4a84b015ed2c51234a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 19 Mar 2021 18:40:37 +0100 Subject: [PATCH] Fixed a memory leak in Settings. --- es-app/src/main.cpp | 1 + es-core/src/Settings.cpp | 9 +++++++++ es-core/src/Settings.h | 1 + 3 files changed, 11 insertions(+) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 9a5d1eff1..75510a613 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -616,6 +616,7 @@ int main(int argc, char* argv[]) CollectionSystemsManager::deinit(); SystemData::deleteSystems(); NavigationSounds::getInstance()->deinit(); + Settings::deinit(); // Call this ONLY when linking with FreeImage as a static library. #if defined(FREEIMAGE_LIB) diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 963b80532..512eafc2a 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -72,10 +72,19 @@ Settings* Settings::getInstance() return sInstance; } +void Settings::deinit() +{ + if (sInstance) { + delete sInstance; + sInstance = nullptr; + } +} + void Settings::setDefaults() { mBoolMap.clear(); mIntMap.clear(); + mStringMap.clear(); // All settings are in pairs of default values and current values. // As such, in this function we set these pairs identically. diff --git a/es-core/src/Settings.h b/es-core/src/Settings.h index e657126d6..822fc27ce 100644 --- a/es-core/src/Settings.h +++ b/es-core/src/Settings.h @@ -18,6 +18,7 @@ class Settings { public: static Settings* getInstance(); + static void deinit(); void loadFile(); void saveFile();