From b5ee2773a083bc39b7d50c9f7064a557cae171d0 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Mon, 23 Apr 2018 12:57:23 +0200 Subject: [PATCH] CppEditor: Use QPointer to 'this' for refactoringEngine calls RefactoringEngine does not depend on CppEditorWidget therefore we should check that the pointer is still valid in the lambda calls. Hopefully fixes QTCREATORBUG-20111 though this fix does not directly address the stack trace. Task-number: QTCREATORBUG-20111 Change-Id: I37f996de60cebe61e290fe181d75fb266f93c1c1 Reviewed-by: Nikolai Kosjar --- src/plugins/cppeditor/cppeditorwidget.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 3ba8d40548e..f2c81a74deb 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -434,10 +434,14 @@ void CppEditorWidget::findUsages(QTextCursor cursor) { if (cursor.isNull()) cursor = textCursor(); + // 'this' in cursorInEditor is never used (and must never be used) asynchronously. const CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this}; + QPointer cppEditorWidget = this; refactoringEngine().findUsages(cursorInEditor, - [this, cursor](const CppTools::Usages &usages) { - findRenameCallback(this, cursor, usages); + [=](const CppTools::Usages &usages) { + if (!cppEditorWidget) + return; + findRenameCallback(cppEditorWidget.data(), cursor, usages); }); } @@ -446,10 +450,13 @@ void CppEditorWidget::renameUsages(const QString &replacement, QTextCursor curso if (cursor.isNull()) cursor = textCursor(); CppTools::CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this}; + QPointer cppEditorWidget = this; refactoringEngine().globalRename(cursorInEditor, - [this, cursor, &replacement](const CppTools::Usages &usages) { - findRenameCallback(this, cursor, usages, true, - replacement); + [=](const CppTools::Usages &usages) { + if (!cppEditorWidget) + return; + findRenameCallback(cppEditorWidget.data(), cursor, usages, + true, replacement); }, replacement); }