From ccb8d0e973eeae38cb63a8a38ba24a6953c583a2 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 15 Jul 2014 09:10:54 +1000 Subject: [PATCH] Fix crash: a reference to a string in a widget was used after the widget was deleted. --- src/states_screens/dialogs/gp_info_dialog.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 36fc61646..f9cdf80c1 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -259,15 +259,19 @@ void GPInfoDialog::onEnterPressedInternal() // ---------------------------------------------------------------------------- -GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventSource) +GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& event_source) { - if (eventSource == "start" || eventSource == "continue") + if (event_source == "start" || event_source == "continue") { // Save GP identifier, since dismiss will delete this object. std::string gp_id = m_gp->getId(); + // Also create a copy of the string: it is a reference to data + // in a widget in the dialog - so if we call dismiss, this reference + // becomes invalid! + std::string save_source = event_source; ModalDialog::dismiss(); race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, - (eventSource == "continue")); + (save_source == "continue")); return GUIEngine::EVENT_BLOCK; }