From c22ddbc187771cec394bcb2c43e65f171cca0182 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 27 Sep 2022 13:41:37 +0200 Subject: [PATCH] decodebin3: Fix memory issues with active selection list This had a couple of issues: * The backing strings (from GstStream) could disappear * The actual list wasn't properly reset/freed when decodebin3 was re-used Part-of: --- .../gst-plugins-base/gst/playback/gstdecodebin3.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c b/subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c index 803bebb907..94d64cfd81 100644 --- a/subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c +++ b/subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c @@ -662,7 +662,7 @@ gst_decodebin3_dispose (GObject * object) if (dbin->decodable_factories) g_list_free (dbin->decodable_factories); g_list_free_full (dbin->requested_selection, g_free); - g_list_free (dbin->active_selection); + g_list_free_full (dbin->active_selection, g_free); g_list_free (dbin->to_activate); g_list_free (dbin->pending_select_streams); g_clear_object (&dbin->collection); @@ -1800,8 +1800,9 @@ get_output_for_slot (MultiQueueSlot * slot) output->slot = slot; GST_DEBUG ("Linking slot %p to new output %p", slot, output); slot->output = output; + GST_DEBUG ("Adding '%s' to active_selection", stream_id); dbin->active_selection = - g_list_append (dbin->active_selection, (gchar *) stream_id); + g_list_append (dbin->active_selection, (gchar *) g_strdup (stream_id)); } else GST_DEBUG ("Not creating any output for slot %p", slot); @@ -2641,8 +2642,10 @@ reassign_slot (GstDecodebin3 * dbin, MultiQueueSlot * slot) slot->output = NULL; output->slot = NULL; /* Remove sid from active selection */ + GST_DEBUG ("Removing '%s' from active_selection", sid); for (tmp = dbin->active_selection; tmp; tmp = tmp->next) if (!g_strcmp0 (sid, tmp->data)) { + g_free (tmp->data); dbin->active_selection = g_list_delete_link (dbin->active_selection, tmp); break; } @@ -2660,7 +2663,7 @@ reassign_slot (GstDecodebin3 * dbin, MultiQueueSlot * slot) /* Pass target stream id to requested selection */ dbin->requested_selection = g_list_append (dbin->requested_selection, g_strdup (tmp->data)); - dbin->to_activate = g_list_remove (dbin->to_activate, tmp->data); + dbin->to_activate = g_list_delete_link (dbin->to_activate, tmp); break; } } @@ -2670,8 +2673,9 @@ reassign_slot (GstDecodebin3 * dbin, MultiQueueSlot * slot) target_slot, tsid); target_slot->output = output; output->slot = target_slot; + GST_DEBUG ("Adding '%s' to active_selection", tsid); dbin->active_selection = - g_list_append (dbin->active_selection, (gchar *) tsid); + g_list_append (dbin->active_selection, (gchar *) g_strdup (tsid)); SELECTION_UNLOCK (dbin); /* Wakeup the target slot so that it retries to send events/buffers @@ -3182,6 +3186,8 @@ gst_decodebin3_change_state (GstElement * element, GstStateChange transition) dbin->default_mq_min_interleave, NULL); dbin->current_mq_min_interleave = dbin->default_mq_min_interleave; dbin->upstream_selected = FALSE; + g_list_free_full (dbin->active_selection, g_free); + dbin->active_selection = NULL; } break; default: