From 0ce28a46a2b02469e5c83c6750d10f5a6d23eb6f Mon Sep 17 00:00:00 2001 From: Levi Pearson Date: Sat, 28 Jan 2017 22:32:17 -0700 Subject: [PATCH] Misc cleanups; memory leaks, use-after-free, use of uninitialized data There are still a bunch of tiny leaks related to the animation Tween data that I haven't figured out how to resolve, but it runs more cleanly now. --- RetroFE/Source/Database/Configuration.cpp | 2 +- RetroFE/Source/Database/MetadataDatabase.cpp | 10 ++++++++-- RetroFE/Source/Graphics/Page.cpp | 3 +++ RetroFE/Source/RetroFE.cpp | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 8e003b7..3a656d1 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -85,7 +85,7 @@ void Configuration::initialize() if(rootPos!=std::string::npos) sPath = sPath.erase(rootPos); #else - char exepath[1024]; + char exepath[1024] = {}; sprintf(exepath, "/proc/%d/exe", getpid()); readlink(exepath, exepath, sizeof(exepath)); std::string sPath(exepath); diff --git a/RetroFE/Source/Database/MetadataDatabase.cpp b/RetroFE/Source/Database/MetadataDatabase.cpp index d1698b9..7e4228d 100644 --- a/RetroFE/Source/Database/MetadataDatabase.cpp +++ b/RetroFE/Source/Database/MetadataDatabase.cpp @@ -327,12 +327,14 @@ void MetadataDatabase::injectMetadata(CollectionInfo *collection) } rc = sqlite3_step(stmt); } + sqlite3_finalize(stmt); } bool MetadataDatabase::needsRefresh() { sqlite3 *handle = db_.handle; sqlite3_stmt *stmt; + bool result; sqlite3_prepare_v2(handle, "SELECT COUNT(*) FROM Meta;", @@ -357,12 +359,16 @@ bool MetadataDatabase::needsRefresh() #endif time_t metadirTime = timeDir(Utils::combinePath(Configuration::absolutePath, "meta")); - return (count == 0 || metadbErr || metadb.st_mtime < metadirTime || exeErr || metadb.st_mtime < exe.st_mtime) ? true : false; + result = (count == 0 || metadbErr || metadb.st_mtime < metadirTime || exeErr || metadb.st_mtime < exe.st_mtime) ? true : false; } else { - return true; + result = true; } + + sqlite3_finalize(stmt); + + return result; } bool MetadataDatabase::importHyperlist(std::string hyperlistFile, std::string collectionName) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 1fc1229..375a0b5 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -523,7 +523,10 @@ bool Page::popCollection() playlist_ = info->playlist; playlistChange(); + // Remove references to the collection we're about to delete and pop the menu menuDepth_--; + activeMenu_->collectionName = ""; + activeMenu_->setItems(NULL); activeMenu_ = menus_[menuDepth_ - 1]; for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 278b466..4a3f8a4 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -914,6 +914,7 @@ CollectionInfo *RetroFE::getCollection(std::string collectionName) } } } + closedir(dp); bool menuSort = true; config_.getProperty("collections." + collectionName + ".list.menuSort", menuSort);