Qt: Fix cleanup leaks
Vicki Pfau vi@endrift.com
Mon, 03 Sep 2018 13:03:14 -0700
2 files changed,
13 insertions(+),
3 deletions(-)
M
src/platform/qt/GBAApp.cpp
→
src/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.h
→
src/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 {