From fba06cfc76d698e3f770721b5c9cc557423dfcdb Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Thu, 16 Mar 2023 23:09:53 +0900 Subject: [PATCH] wasapi2: Fix potential crash on device activation failure The activation object is live in COM thread already and therefore self refcount hack is pointless. Part-of: --- .../sys/wasapi2/gstwasapi2client.cpp | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2client.cpp b/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2client.cpp index b2d1ac8472..72bcc8393e 100644 --- a/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2client.cpp +++ b/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2client.cpp @@ -144,7 +144,6 @@ public: client = (GstWasapi2Client *) g_weak_ref_get (&listener_); if (!client) { - this->Release (); GST_WARNING ("No listener was configured"); return S_OK; } @@ -177,8 +176,6 @@ public: * by passed IAudioClient handle via gst_wasapi2_client_on_device_activated */ - this->Release (); - return S_OK; } @@ -231,17 +228,6 @@ public: hr = work_item->Invoke (); } - /* We should hold activator object until activation callback has executed, - * because OS doesn't hold reference of this callback COM object. - * otherwise access violation would happen - * See https://docs.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-activateaudiointerfaceasync - * - * This reference count will be decreased by self later on callback, - * which will be called from device worker thread. - */ - if (gst_wasapi2_result (hr)) - this->AddRef (); - return hr; } @@ -404,9 +390,6 @@ static void gst_wasapi2_client_constructed (GObject * object) { GstWasapi2Client *self = GST_WASAPI2_CLIENT (object); - /* *INDENT-OFF* */ - ComPtr activator; - /* *INDENT-ON* */ /* Create a new thread to ensure that COM thread can be MTA thread. * We cannot ensure whether CoInitializeEx() was called outside of here for @@ -959,6 +942,10 @@ run_loop: g_main_context_pop_thread_default (self->context); + /* Wait for pending async op if any */ + if (self->dispatcher) + gst_wasapi2_client_ensure_activation (self); + GST_WASAPI2_CLEAR_COM (self->audio_client); /* Reset explicitly to ensure that it happens before