1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

ListenerList: Fix rare use-after-free when assertions are enabled

This issue manifested on Linux when building in Debug mode. It may also
have caused issues on other platforms. When editing a slider's value
using its text box, and then pressing the enter key, the program would
crash. The issue was not present when running with address sanitizer.
Valgrind was able to find the problem.
This commit is contained in:
reuk 2024-11-07 16:22:22 +00:00
parent 7437e35ef5
commit 0ea1af03a1
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -230,7 +230,10 @@ public:
Callback&& callback)
{
#if JUCE_ASSERTIONS_ENABLED_OR_LOGGED
const ScopedTryLock callCheckedExcludingLock (*callCheckedExcludingMutex);
// Keep a reference to the mutex to protect against the case where this list gets deleted
// during a callback.
auto localMutexPtr = callCheckedExcludingMutex;
const ScopedTryLock callCheckedExcludingLock (*localMutexPtr);
// If you hit this assertion it means you're trying to call the listeners from multiple
// threads concurrently. If you need to do this either use a LightweightListenerList, for a
@ -396,9 +399,9 @@ private:
}
#if JUCE_ASSERTIONS_ENABLED_OR_LOGGED
// using a unique_ptr helps keep the size of this class down to prevent excessive stack sizes
// using a shared_ptr helps keep the size of this class down to prevent excessive stack sizes
// due to objects that contain a ListenerList being created on the stack
std::unique_ptr<CriticalSection> callCheckedExcludingMutex = std::make_unique<CriticalSection>();
std::shared_ptr<CriticalSection> callCheckedExcludingMutex = std::make_shared<CriticalSection>();
#endif
//==============================================================================