Bug 1263514 - Handle notification registering failure in cubeb_wasapi.cpp. r?kinetik
MozReview-Commit-ID: 8j5MDjq8Lnb
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -916,31 +916,44 @@ HRESULT register_notification_client(cub
return hr;
}
stm->notification_client = new wasapi_endpoint_notification_client(stm->reconfigure_event);
hr = stm->device_enumerator->RegisterEndpointNotificationCallback(stm->notification_client);
if (FAILED(hr)) {
LOG("Could not register endpoint notification callback: %x\n", hr);
+ delete stm->notification_client;
+ stm->notification_client = nullptr;
return hr;
}
+ stm->notification_client->AddRef();
+
return hr;
}
HRESULT unregister_notification_client(cubeb_stream * stm)
{
XASSERT(stm);
+ HRESULT hr;
if (!stm->device_enumerator) {
return S_OK;
}
- stm->device_enumerator->UnregisterEndpointNotificationCallback(stm->notification_client);
+ hr = stm->device_enumerator->UnregisterEndpointNotificationCallback(stm->notification_client);
+ if (FAILED(hr)) {
+ // We can't really do anything here, we'll probably leak the
+ // notification client, but we can at least release the enumerator.
+ SafeRelease(stm->device_enumerator);
+ return S_OK;
+ }
+
+ stm->notification_client->Release();
SafeRelease(stm->notification_client);
SafeRelease(stm->device_enumerator);
return S_OK;
}
HRESULT get_endpoint(IMMDevice ** device, LPCWSTR devid)