hlsdemux2: Fix memory leaks

Clean up various memory leaks

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2676>
This commit is contained in:
Jan Schmidt 2022-06-24 02:57:03 +10:00 committed by GStreamer Marge Bot
parent 76e0333213
commit b2944c36ca
2 changed files with 29 additions and 2 deletions

View file

@ -683,6 +683,9 @@ gst_hls_demux_stream_update_tracks (GstAdaptiveDemux * demux,
gst_adaptive_demux_track_unref (track); gst_adaptive_demux_track_unref (track);
} }
if (variant_caps)
gst_caps_unref (variant_caps);
/* Update the stream object with rendition types. /* Update the stream object with rendition types.
* FIXME: rendition_type could be removed */ * FIXME: rendition_type could be removed */
stream->stream_type = hlsdemux_stream->rendition_type; stream->stream_type = hlsdemux_stream->rendition_type;
@ -814,6 +817,8 @@ gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
/* Is this rendition active in the current variant ? */ /* Is this rendition active in the current variant ? */
if (!g_strcmp0 (playlist->media_groups[media->mtype], media->group_id)) { if (!g_strcmp0 (playlist->media_groups[media->mtype], media->group_id)) {
GST_DEBUG_OBJECT (demux, "Enabling rendition"); GST_DEBUG_OBJECT (demux, "Enabling rendition");
if (media_stream->current_rendition)
gst_hls_rendition_stream_unref (media_stream->current_rendition);
media_stream->current_rendition = gst_hls_rendition_stream_ref (media); media_stream->current_rendition = gst_hls_rendition_stream_ref (media);
} }
@ -821,6 +826,10 @@ gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
streams = g_list_append (streams, media_stream); streams = g_list_append (streams, media_stream);
} }
/* Free the list (but not the contents, which are stored
* elsewhere */
if (streams)
g_list_free (streams);
create_main_variant_stream (hlsdemux); create_main_variant_stream (hlsdemux);
@ -873,6 +882,10 @@ gst_hls_demux_process_manifest (GstAdaptiveDemux * demux, GstBuffer * buf)
return FALSE; return FALSE;
} }
if (hlsdemux->master) {
gst_hls_master_playlist_unref (hlsdemux->master);
hlsdemux->master = NULL;
}
hlsdemux->master = gst_hls_master_playlist_new_from_data (playlist, hlsdemux->master = gst_hls_master_playlist_new_from_data (playlist,
gst_adaptive_demux_get_manifest_ref_uri (demux)); gst_adaptive_demux_get_manifest_ref_uri (demux));
@ -1656,6 +1669,9 @@ gst_hls_demux_stream_finalize (GObject * object)
if (hls_stream == hlsdemux->main_stream) if (hls_stream == hlsdemux->main_stream)
hlsdemux->main_stream = NULL; hlsdemux->main_stream = NULL;
g_free (hls_stream->lang);
g_free (hls_stream->name);
if (hls_stream->playlist) { if (hls_stream->playlist) {
gst_hls_media_playlist_unref (hls_stream->playlist); gst_hls_media_playlist_unref (hls_stream->playlist);
hls_stream->playlist = NULL; hls_stream->playlist = NULL;
@ -1668,6 +1684,9 @@ gst_hls_demux_stream_finalize (GObject * object)
gst_buffer_replace (&hls_stream->pending_typefind_buffer, NULL); gst_buffer_replace (&hls_stream->pending_typefind_buffer, NULL);
gst_buffer_replace (&hls_stream->pending_segment_data, NULL); gst_buffer_replace (&hls_stream->pending_segment_data, NULL);
if (hls_stream->moov)
gst_isoff_moov_box_free (hls_stream->moov);
if (hls_stream->current_key) { if (hls_stream->current_key) {
g_free (hls_stream->current_key); g_free (hls_stream->current_key);
hls_stream->current_key = NULL; hls_stream->current_key = NULL;
@ -2167,6 +2186,7 @@ gst_hls_demux_update_fragment_info (GstAdaptiveDemux2Stream * stream)
if (GST_ADAPTIVE_DEMUX2_STREAM_NEED_HEADER (stream) && file->init_file) { if (GST_ADAPTIVE_DEMUX2_STREAM_NEED_HEADER (stream) && file->init_file) {
GstM3U8InitFile *header_file = file->init_file; GstM3U8InitFile *header_file = file->init_file;
g_free (stream->fragment.header_uri);
stream->fragment.header_uri = g_strdup (header_file->uri); stream->fragment.header_uri = g_strdup (header_file->uri);
stream->fragment.header_range_start = header_file->offset; stream->fragment.header_range_start = header_file->offset;
if (header_file->size != -1) { if (header_file->size != -1) {

View file

@ -1467,6 +1467,8 @@ gst_hls_rendition_stream_unref (GstHLSRenditionStream * media)
{ {
g_assert (media != NULL && media->ref_count > 0); g_assert (media != NULL && media->ref_count > 0);
if (g_atomic_int_dec_and_test (&media->ref_count)) { if (g_atomic_int_dec_and_test (&media->ref_count)) {
if (media->caps)
gst_caps_unref (media->caps);
g_free (media->group_id); g_free (media->group_id);
g_free (media->name); g_free (media->name);
g_free (media->uri); g_free (media->uri);
@ -1795,6 +1797,8 @@ void
hls_master_playlist_unref (GstHLSMasterPlaylist * playlist) hls_master_playlist_unref (GstHLSMasterPlaylist * playlist)
{ {
if (g_atomic_int_dec_and_test (&playlist->refcount)) { if (g_atomic_int_dec_and_test (&playlist->refcount)) {
g_list_free_full (playlist->renditions,
(GDestroyNotify) gst_hls_rendition_stream_unref);
g_list_free_full (playlist->variants, g_list_free_full (playlist->variants,
(GDestroyNotify) gst_hls_variant_stream_unref); (GDestroyNotify) gst_hls_variant_stream_unref);
g_list_free_full (playlist->iframe_variants, g_list_free_full (playlist->iframe_variants,
@ -2134,13 +2138,14 @@ hls_master_playlist_new_from_data (gchar * data, const gchar * base_uri)
GST_PTR_FORMAT, media->caps); GST_PTR_FORMAT, media->caps);
} else { } else {
GST_DEBUG (" Assigning caps %" GST_PTR_FORMAT, media_caps); GST_DEBUG (" Assigning caps %" GST_PTR_FORMAT, media_caps);
media->caps = gst_caps_ref (media_caps); gst_caps_replace (&media->caps, media_caps);
} }
} }
} }
if (!alt_in_variant) { if (!alt_in_variant) {
GstCaps *new_caps = gst_caps_subtract (stream->caps, media_caps); GstCaps *new_caps = gst_caps_subtract (stream->caps, media_caps);
gst_caps_replace (&stream->caps, new_caps); gst_caps_replace (&stream->caps, new_caps);
gst_caps_unref (new_caps);
} }
gst_caps_unref (media_caps); gst_caps_unref (media_caps);
} }
@ -2274,7 +2279,9 @@ hls_master_playlist_get_common_caps (GstHLSMasterPlaylist * playlist)
if (!res) { if (!res) {
res = gst_caps_copy (stream->caps); res = gst_caps_copy (stream->caps);
} else { } else {
res = gst_caps_merge_common (res, stream->caps); GstCaps *common_caps = gst_caps_merge_common (res, stream->caps);
gst_caps_unref (res);
res = common_caps;
if (!res) if (!res)
goto beach; goto beach;
} }