Skip to content

Commit bc25aa3

Browse files
authored
Fix crash from joining the event thread on itself (#1047)
1 parent b17c0b9 commit bc25aa3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/debuggercontroller.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,8 +1875,18 @@ void DebuggerController::EventHandler(const DebuggerEvent& event)
18751875

18761876
if (m_accessor)
18771877
{
1878-
delete m_accessor;
1878+
// Defer deletion to a detached thread. The accessor holds a DbgRef<DebuggerController>,
1879+
// and if it is the last reference, deleting it here (on the event thread) would trigger
1880+
// ~DebuggerController which calls m_debuggerEventThread.join() -- deadlocking/crashing
1881+
// because we ARE the event thread.
1882+
//
1883+
// This can happen when Destroy() races with event processing: EventHandler sets
1884+
// ConnectionStatus to NotConnected (line above), and another thread observes this,
1885+
// calls Destroy() which removes the global array ref, making the accessor's DbgRef
1886+
// the last reference to the controller.
1887+
auto* accessor = m_accessor;
18791888
m_accessor = nullptr;
1889+
std::thread([accessor]() { delete accessor; }).detach();
18801890
}
18811891
m_lastIP = m_currentIP;
18821892
m_currentIP = 0;

0 commit comments

Comments
 (0)