From ab09184efffdd70c5c89f20895132c7900777f7d Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 27 Sep 2019 22:04:49 +0100 Subject: Avoid lambda being destroyed while it is being called. Also armor against mpDialogImpl going down during EndDialog. This can happen during an insert chart wizard cancel, as out of place embedded dialog cleanup occurs. Change-Id: I1b666f07d4ec72e07fdf6888cea44a5a13976073 Reviewed-on: https://gerrit.libreoffice.org/79772 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks Reviewed-on: https://gerrit.libreoffice.org/79778 Tested-by: Jenkins --- vcl/source/window/dialog.cxx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 1748abd0272a..080b64416e01 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -1163,13 +1163,13 @@ void Dialog::EndDialog( long nResult ) if ( mpDialogImpl->mbStartedModal ) ImplEndExecuteModal(); - if (mpDialogImpl->maEndCtx.isSet()) + if ( mpDialogImpl && mpDialogImpl->maEndCtx.isSet() ) { - mpDialogImpl->maEndCtx.maEndDialogFn(nResult); - mpDialogImpl->maEndCtx.maEndDialogFn = nullptr; + auto fn = std::move(mpDialogImpl->maEndCtx.maEndDialogFn); + fn(nResult); } - if ( mpDialogImpl->mbStartedModal ) + if ( mpDialogImpl && mpDialogImpl->mbStartedModal ) { mpDialogImpl->mbStartedModal = false; mpDialogImpl->mnResult = -1; @@ -1177,12 +1177,15 @@ void Dialog::EndDialog( long nResult ) mbInExecute = false; - // Destroy ourselves (if we have a context with VclPtr owner) - std::shared_ptr xOwnerDialogController = std::move(mpDialogImpl->maEndCtx.mxOwnerDialogController); - std::shared_ptr xOwnerSelf = std::move(mpDialogImpl->maEndCtx.mxOwnerSelf); - mpDialogImpl->maEndCtx.mxOwner.disposeAndClear(); - xOwnerDialogController.reset(); - xOwnerSelf.reset(); + if ( mpDialogImpl ) + { + // Destroy ourselves (if we have a context with VclPtr owner) + std::shared_ptr xOwnerDialogController = std::move(mpDialogImpl->maEndCtx.mxOwnerDialogController); + std::shared_ptr xOwnerSelf = std::move(mpDialogImpl->maEndCtx.mxOwnerSelf); + mpDialogImpl->maEndCtx.mxOwner.disposeAndClear(); + xOwnerDialogController.reset(); + xOwnerSelf.reset(); + } } void Dialog::EndAllDialogs( vcl::Window const * pParent ) -- cgit