Bug 1263514 - Handle notification registering failure in cubeb_wasapi.cpp. r?kinetik draft
authorPaul Adenot <paul@paul.cx>
Fri, 15 Apr 2016 11:42:08 +0200
changeset 351952 1e39ca4919b16d7f78378b498d57334c099ca20c
parent 349268 29d5a4175c8b74f45482276a53985cf2568b4be2
child 518534 13219510441f376548482a4cd2f9bf20441a3825
push id15564
push userpaul@paul.cx
push dateFri, 15 Apr 2016 09:42:16 +0000
reviewerskinetik
bugs1263514
milestone48.0a1
Bug 1263514 - Handle notification registering failure in cubeb_wasapi.cpp. r?kinetik MozReview-Commit-ID: 8j5MDjq8Lnb
media/libcubeb/src/cubeb_wasapi.cpp
--- 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)