Qt: Fix memory leak in library

This commit is contained in:
Vicki Pfau 2020-02-21 00:58:34 -08:00
parent fc29595a1c
commit c8d1695c54
2 changed files with 12 additions and 3 deletions

View File

@ -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<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 @@ 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);
}

View File

@ -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<mLibrary> m_library;