Bug 1367646 - Let cubeb_device_collection_destroy handle invalid collections. r?kinetik
This can be upstreamed.
MozReview-Commit-ID: 5a2lxV6Y1yT
--- 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)