all repos — mgba @ a052feda88017f2ec5e3f38f78b1f835a78669bf

mGBA Game Boy Advance Emulator

Qt: Fix cleanup leaks
Vicki Pfau vi@endrift.com
Mon, 03 Sep 2018 13:03:14 -0700
commit

a052feda88017f2ec5e3f38f78b1f835a78669bf

parent

f951cebc10550d45ff0e253882573a625d2ae6e5

2 files changed, 13 insertions(+), 3 deletions(-)

jump to
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -64,10 +64,20 @@

if (!m_configController->getQtOption("audioDriver").isNull()) { AudioProcessor::setDriver(static_cast<AudioProcessor::Driver>(m_configController->getQtOption("audioDriver").toInt())); } + + connect(this, &GBAApp::aboutToQuit, this, &GBAApp::cleanup); } -GBAApp::~GBAApp() { +void GBAApp::cleanup() { m_workerThreads.waitForDone(); + + while (!m_workerJobs.isEmpty()) { + finishJob(m_workerJobs.firstKey()); + } + + if (m_db) { + NoIntroDBDestroy(m_db); + } } bool GBAApp::event(QEvent* event) {

@@ -177,7 +187,7 @@ if (db && m_db) {

NoIntroDBDestroy(m_db); } if (db) { - GameDBParser* parser = new GameDBParser(db); + std::shared_ptr<GameDBParser> parser = std::make_shared<GameDBParser>(db); submitWorkerJob(std::bind(&GameDBParser::parseNoIntroDB, parser)); m_db = db; return true;
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -52,7 +52,6 @@ Q_OBJECT

public: GBAApp(int& argc, char* argv[], ConfigController*); - ~GBAApp(); static GBAApp* app(); static QString dataDir();

@@ -79,6 +78,7 @@ bool event(QEvent*);

private slots: void finishJob(qint64 jobId); + void cleanup(); private: class WorkerJob : public QRunnable {