Qt: Fix memory leak in library
Vicki Pfau vi@endrift.com
Fri, 21 Feb 2020 00:58:34 -0800
2 files changed,
12 insertions(+),
3 deletions(-)
M
src/platform/qt/library/LibraryController.cpp
→
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 "GBAApp.h"
#include "LibraryGrid.h" #include "LibraryTree.h" -namespace QGBA { +using namespace QGBA; LibraryEntry::LibraryEntry(mLibraryEntry* entry) : entry(entry)@@ -57,6 +58,7 @@ refresh();
} LibraryController::~LibraryController() { + freeLibrary(); mLibraryListingDeinit(&m_listing); }@@ -134,7 +136,7 @@
QStringList allEntries; QList<LibraryEntryRef> 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 @@ std::shared_ptr<mLibrary> library = m_library;
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); +}
M
src/platform/qt/library/LibraryController.h
→
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 @@ void refresh();
private: void loadDirectory(const QString&); // Called on separate thread + void freeLibrary(); ConfigController* m_config = nullptr; std::shared_ptr<mLibrary> m_library;