ClangTools: Fix crash when starting the analyzer again

Address a nullptr dereference of m_runWorker in
ClangTool::updateForCurrentState() for the case described as (C2) below,
reproducible with "./qtcreator -test ClangTools".

Two use cases are connected to this:

 (C1) Run the analyzer twice with clearing app output pane in-between
 (C2) Run the analyzer twice without clearing app output pane in-between

Relevant observations in this context are:

 (O1) Closing the app output pane destroys the RunControl/RunWorker.
 (O2) Running the analyzer a second time will first create a new
 RunControl/RunWorker, then destroy the old one.

Now, the change

    ClangTools: Avoid accessing deleted run worker
    This reverts commit d02f5664e5.

fixed a use-after-free-crash for (C1), but introduced a
nullptr-deref-crash for (C2) as it resets m_runWorker to nullptr on
RunControl destruction, which conflicts with the order mentioned in
(O2).

To fix both use cases, revert the mentioned change and access
m_runWorker only when we know that it exists for sure - right after
signal emission.

Change-Id: I034f0905d635b15c0c6bbe499648b62d5a058c04
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Nikolai Kosjar
2020-05-14 09:28:47 +02:00
parent c59e8ce651
commit 9edf0056ae
2 changed files with 19 additions and 11 deletions

View File

@@ -162,6 +162,9 @@ private:
QAction *m_stopAction = nullptr;
State m_state = State::Initial;
int m_filesCount = 0;
int m_filesSucceeded = 0;
int m_filesFailed = 0;
DiagnosticFilterModel *m_diagnosticFilterModel = nullptr;