From 1dc94c999a15df2313c798931b89628c9aaa6128 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 16 Jul 2023 22:02:18 -0700 Subject: [PATCH] Qt: Fix leak if loading a save file fails --- src/platform/qt/CoreController.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/platform/qt/CoreController.cpp b/src/platform/qt/CoreController.cpp index 165350945..fa0684466 100644 --- a/src/platform/qt/CoreController.cpp +++ b/src/platform/qt/CoreController.cpp @@ -775,10 +775,14 @@ void CoreController::loadSave(const QString& path, bool temporary) { return; } + bool ok; if (temporary) { - m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); + ok = m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); } else { - m_threadContext.core->loadSave(m_threadContext.core, vf); + ok = m_threadContext.core->loadSave(m_threadContext.core, vf); + } + if (!ok) { + vf->close(vf); } }); if (hasStarted()) { @@ -788,10 +792,14 @@ void CoreController::loadSave(const QString& path, bool temporary) { void CoreController::loadSave(VFile* vf, bool temporary) { m_resetActions.append([this, vf, temporary]() { + bool ok; if (temporary) { - m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); + ok = m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); } else { - m_threadContext.core->loadSave(m_threadContext.core, vf); + ok = m_threadContext.core->loadSave(m_threadContext.core, vf); + } + if (!ok) { + vf->close(vf); } }); if (hasStarted()) {