Bug 1367646 - Let cubeb_device_collection_destroy handle invalid collections. r?kinetik draft
authorDan Glastonbury <dan.glastonbury@gmail.com>
Fri, 26 May 2017 11:23:55 +1000
changeset 584879 73284e8985cb315946c450b68f8c2272efb87ff1
parent 584878 a54804c18a4ce99acf77f2bf0733da81d312fdab
child 584880 22881cb90be852679002600b346ccd3c05cc8499
push id60918
push userbmo:dglastonbury@mozilla.com
push dateFri, 26 May 2017 06:28:26 +0000
reviewerskinetik
bugs1367646
milestone55.0a1
Bug 1367646 - Let cubeb_device_collection_destroy handle invalid collections. r?kinetik This can be upstreamed. MozReview-Commit-ID: 5a2lxV6Y1yT
media/libcubeb/src/cubeb.c
--- a/media/libcubeb/src/cubeb.c
+++ b/media/libcubeb/src/cubeb.c
@@ -569,23 +569,34 @@ int cubeb_enumerate_devices(cubeb * cont
   }
 
   return rv;
 }
 
 int cubeb_device_collection_destroy(cubeb * context,
                                     cubeb_device_collection * collection)
 {
-  if (context == NULL || collection == NULL)
+  int r;
+
+  if (!context || !collection)
     return CUBEB_ERROR_INVALID_PARAMETER;
 
   if (!context->ops->device_collection_destroy)
     return CUBEB_ERROR_NOT_SUPPORTED;
 
-  return context->ops->device_collection_destroy(context, collection);
+  if (!collection->device)
+    return CUBEB_OK;
+
+  r = context->ops->device_collection_destroy(context, collection);
+  if (r == CUBEB_OK) {
+    collection->device = NULL;
+    collection->count = 0;
+  }
+
+  return r;
 }
 
 int cubeb_register_device_collection_changed(cubeb * context,
                                              cubeb_device_type devtype,
                                              cubeb_device_collection_changed_callback callback,
                                              void * user_ptr)
 {
   if (context == NULL || (devtype & (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT)) == 0)