aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-04-23 12:57:23 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-04-24 14:31:45 +0000
commitb5ee2773a083bc39b7d50c9f7064a557cae171d0 (patch)
tree0faa57b051cf71b8c33d17a9d17f86e2b6c69ca3
parentfeac99c9acb49c423ec2392df803f07a0f199b6f (diff)
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 <nikolai.kosjar@qt.io>
-rw-r--r--src/plugins/cppeditor/cppeditorwidget.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp
index 3ba8d40548..f2c81a74de 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> 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> 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);
}