From afa66ab9c7c5ff7baa5826f554463ca48165f198 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 2 Jul 2013 14:52:10 +0200 Subject: [PATCH] C++: fix potential deadlock when closing an editor When the editor is closed, the CppEditorSupport waits for the highlighting and semantic info futures to finish. These futures might access the CppEditorSupport through the CppModelManager, causing a deadlock on the m_editorSupportMutex. Change-Id: Ifeb3864ed3bc2666d83607ef50d7bfee8f3d118f Reviewed-by: Eike Ziller Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/cppmodelmanager.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index b7abbe2d2dc..76b8c4e0e50 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -615,9 +615,14 @@ void CppModelManager::deleteEditorSupport(TextEditor::BaseTextEditor *textEditor if (!isCppEditor(textEditor)) return; - QMutexLocker locker(&m_editorSupportMutex); - CppEditorSupport *editorSupport = m_editorSupport.value(textEditor, 0); - m_editorSupport.remove(textEditor); + CppEditorSupport *editorSupport; + + { // only lock the operations on m_editorSupport + QMutexLocker locker(&m_editorSupportMutex); + editorSupport = m_editorSupport.value(textEditor, 0); + m_editorSupport.remove(textEditor); + } + delete editorSupport; }