[all-commits] [llvm/llvm-project] 6b5c55: [lldb] Fix 10 year old leak of `g_debugger_list_pt...
Jonas Devlieghere via All-commits
all-commits at lists.llvm.org
Tue Mar 3 13:16:12 PST 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6b5c55ef169cfb19e0159241a5932e593a8e1e3c
https://github.com/llvm/llvm-project/commit/6b5c55ef169cfb19e0159241a5932e593a8e1e3c
Author: Jonas Devlieghere <jonas at devlieghere.com>
Date: 2026-03-03 (Tue, 03 Mar 2026)
Changed paths:
M lldb/source/Core/Debugger.cpp
Log Message:
-----------
[lldb] Fix 10 year old leak of `g_debugger_list_ptr` (#184259)
Roughly 10 years ago, in aacb80853a46bd544fa76a945667302be1de706c, Greg
deleted the call to delete g_debugger_list_ptr because of a race
condition:
> Fixed a threading race condition where we could crash after calling
Debugger::Terminate().
>
> The issue was we have two global variables: one that contains a
DebuggerList pointer and one that contains a std::mutex > pointer. These
get initialized in Debugger::Initialize(), and everywhere that uses
these does:
>
> if (g_debugger_list_ptr && g_debugger_list_mutex_ptr)
> {
> std::lock_guard<std::recursive_mutex>
guard(*g_debugger_list_mutex_ptr);
> // do work while mutex is locked
> }
>
> Debugger::Terminate() was deleting and nulling out g_debugger_list_ptr
which meant we had a race condition where someone might do the if
statement and it evaluates to true, then another thread calls
Debugger::Terminate() and deletes and nulls out g_debugger_list_ptr
while holding the mutex, and another thread then locks the mutex and
tries to use g_debugger_list_ptr. The fix is to just not delete and null
out the g_debugger_list_ptr variable.
However, this isn't necessary as long as we persist ("leak") the mutex
and always check it first. That's exactly what this patch does. Without
it, the assert in Debugger::Initialize is incorrect.
```
assert(g_debugger_list_ptr == nullptr &&
"Debugger::Initialize called more than once!");
```
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list