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:
parent
7437e35ef5
commit
0ea1af03a1
1 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue