From 024a0b4a20bd6d84068176575a5b01909f90a9bf Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 1 Jul 2021 12:55:35 +0100 Subject: [PATCH] FileBasedDocument: Fix use-after-move bug --- .../documents/juce_FileBasedDocument.cpp | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp index 37cba5cac8..56194f626d 100644 --- a/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp +++ b/modules/juce_gui_extra/documents/juce_FileBasedDocument.cpp @@ -440,15 +440,13 @@ private: int askToSaveChanges (SafeParentPointer parent, std::function callback) { - auto wrappedCallback = [parent, callback = std::move (callback)] (int alertResult) - { - if (parent != nullptr) - callback (parent, alertResult); - }; - - auto modalCallback = callback == nullptr - ? nullptr - : ModalCallbackFunction::create (std::move (wrappedCallback)); + auto* modalCallback = callback == nullptr + ? nullptr + : ModalCallbackFunction::create ([parent, callback = std::move (callback)] (int alertResult) + { + if (parent != nullptr) + callback (parent, alertResult); + }); return AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon, TRANS ("Closing document..."), @@ -458,7 +456,7 @@ private: TRANS ("Discard changes"), TRANS ("Cancel"), nullptr, - std::move (modalCallback)); + modalCallback); } //============================================================================== @@ -676,17 +674,13 @@ private: if (parent == nullptr) return false; - auto wrappedCallback = [parent, callback = std::move (callback)] (int r) - { - if (parent == nullptr) - return; - - callback (parent, r == 1); - }; - - auto modalCallback = callback == nullptr - ? nullptr - : ModalCallbackFunction::create (std::move (wrappedCallback)); + auto* modalCallback = callback == nullptr + ? nullptr + : ModalCallbackFunction::create ([parent, callback = std::move (callback)] (int r) + { + if (parent != nullptr) + callback (parent, r == 1); + }); return AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, TRANS ("File already exists"), @@ -697,7 +691,7 @@ private: TRANS ("Overwrite"), TRANS ("Cancel"), nullptr, - std::move (modalCallback)); + modalCallback); } //==============================================================================