element: ref-sink the correct pad template when replacing an existing one

templ is the new one that is being stored and that needs to be ref-sinked,
padtempl is the old one that just needs to be unreffed.

Fixes leaking the old template, and also makes sure that the new template is not
floating which can cause use-after-frees with bindings as they might wrongly
take ownership of a still floating template.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8988>
This commit is contained in:
Sebastian Dröge 2025-05-16 13:11:33 +03:00 committed by GStreamer Marge Bot
parent 6432f6a1f2
commit 08c56f3e2d

View File

@ -1527,8 +1527,8 @@ gst_element_class_add_pad_template (GstElementClass * klass,
/* Found pad with the same name, replace and return */
if (strcmp (templ->name_template, padtempl->name_template) == 0) {
gst_object_ref_sink (padtempl);
gst_object_unref (padtempl);
gst_object_ref_sink (templ);
template_list->data = templ;
return;
}