From 515b255fa45d7037778d7bc1bd1f540f0cf97cd6 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 6 Aug 2023 01:55:55 -0500 Subject: [PATCH] LibAudio: Clear callbacks and disconnect PulseAudioStream in destructor If we don't clear the callbacks, they may be called after our functions are deleted. Disconnecting the stream also doesn't appear to be done automatically when calling `pa_stream_unref()` for the last time, so let's do that. --- Userland/Libraries/LibAudio/PulseAudioWrappers.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Userland/Libraries/LibAudio/PulseAudioWrappers.cpp b/Userland/Libraries/LibAudio/PulseAudioWrappers.cpp index d6c6bb339a..d8415fbf6f 100644 --- a/Userland/Libraries/LibAudio/PulseAudioWrappers.cpp +++ b/Userland/Libraries/LibAudio/PulseAudioWrappers.cpp @@ -266,11 +266,18 @@ ErrorOr> PulseAudioContext::create_stream(Output wait_for_signal(); } + pa_stream_set_state_callback(stream, nullptr, nullptr); + return stream_wrapper; } PulseAudioStream::~PulseAudioStream() { + auto locker = m_context->main_loop_locker(); + pa_stream_set_write_callback(m_stream, nullptr, nullptr); + pa_stream_set_underflow_callback(m_stream, nullptr, nullptr); + pa_stream_set_started_callback(m_stream, nullptr, nullptr); + pa_stream_disconnect(m_stream); pa_stream_unref(m_stream); }