gst: deviceprovider: Fix a leak and a heap-use-after-free

The device passed to gst_device_provider_device_add() is transfer:floating, so
we need increase its ref, otherwise the pointer we keep internally will be a
dangling ref.

Also gst_device_provider_device_remove() doesn't actually release the device, so
we have to do it ourselves.

Fixes #4616
This commit is contained in:
Philippe Normand 2025-03-22 18:33:12 +00:00 committed by Wim Taymans
parent 58c412c9dc
commit 81408597f4

View file

@ -327,6 +327,7 @@ static void do_add_nodes(GstPipeWireDeviceProvider *self)
gst_object_ref_sink (device),
compare_device_session_priority);
} else {
gst_object_ref (device);
gst_device_provider_device_add (GST_DEVICE_PROVIDER (self), device);
}
}
@ -484,7 +485,8 @@ destroy_node (void *data)
}
if (nd->dev != NULL) {
gst_device_provider_device_remove (provider, GST_DEVICE (nd->dev));
gst_device_provider_device_remove (provider, nd->dev);
gst_clear_object (&nd->dev);
}
if (nd->caps)
gst_caps_unref(nd->caps);