From c8d1695c54447d728e8beabddf6c11c9fd824a97 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 21 Feb 2020 00:58:34 -0800 Subject: [PATCH] Qt: Fix memory leak in library --- src/platform/qt/library/LibraryController.cpp | 13 ++++++++++--- src/platform/qt/library/LibraryController.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/platform/qt/library/LibraryController.cpp b/src/platform/qt/library/LibraryController.cpp index b7756437b..51fa6d619 100644 --- a/src/platform/qt/library/LibraryController.cpp +++ b/src/platform/qt/library/LibraryController.cpp @@ -1,4 +1,5 @@ /* Copyright (c) 2014-2017 waddlesplash + * Copyright (c) 2014-2020 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -10,7 +11,7 @@ #include "LibraryGrid.h" #include "LibraryTree.h" -namespace QGBA { +using namespace QGBA; LibraryEntry::LibraryEntry(mLibraryEntry* entry) : entry(entry) @@ -57,6 +58,7 @@ LibraryController::LibraryController(QWidget* parent, const QString& path, Confi } LibraryController::~LibraryController() { + freeLibrary(); mLibraryListingDeinit(&m_listing); } @@ -134,7 +136,7 @@ void LibraryController::refresh() { QStringList allEntries; QList newEntries; - mLibraryListingClear(&m_listing); + freeLibrary(); mLibraryGetEntries(m_library.get(), &m_listing, 0, 0, nullptr); for (size_t i = 0; i < mLibraryListingSize(&m_listing); i++) { mLibraryEntry* entry = mLibraryListingGetPointer(&m_listing, i); @@ -185,4 +187,9 @@ void LibraryController::loadDirectory(const QString& dir) { mLibraryLoadDirectory(library.get(), dir.toUtf8().constData()); } -} +void LibraryController::freeLibrary() { + for (size_t i = 0; i < mLibraryListingSize(&m_listing); ++i) { + mLibraryEntryFree(mLibraryListingGetPointer(&m_listing, i)); + } + mLibraryListingClear(&m_listing); +} \ No newline at end of file diff --git a/src/platform/qt/library/LibraryController.h b/src/platform/qt/library/LibraryController.h index 029b96aaa..9f88cdff5 100644 --- a/src/platform/qt/library/LibraryController.h +++ b/src/platform/qt/library/LibraryController.h @@ -1,4 +1,5 @@ /* Copyright (c) 2014-2017 waddlesplash + * Copyright (c) 2014-2020 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -97,6 +98,7 @@ private slots: private: void loadDirectory(const QString&); // Called on separate thread + void freeLibrary(); ConfigController* m_config = nullptr; std::shared_ptr m_library;