hlsdemux2: m3u8: Fix memory leaks on parsing
authorJan Schmidt <jan@centricular.com>
Wed, 10 Aug 2022 19:36:15 +0000 (05:36 +1000)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 12 Aug 2022 13:52:59 +0000 (13:52 +0000)
Fix memory leaks when parsing of an m3u8 file is
incomplete, with EXTINF or EXT-X-PROGRAM-DATE-TIME
directives, but no segment url.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>

subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c

index b0a1161..cc2fdce 100644 (file)
@@ -509,6 +509,7 @@ gst_hls_media_playlist_parse (gchar * data, const gchar * uri,
         data = NULL;
         date_time = NULL;
         duration = 0;
+        g_free (title);
         title = NULL;
         discontinuity = FALSE;
         size = offset = -1;
@@ -552,9 +553,9 @@ gst_hls_media_playlist_parse (gchar * data, const gchar * uri,
         if (last_init_file)
           file->init_file = gst_m3u8_init_file_ref (last_init_file);
 
-        date_time = NULL;
+        date_time = NULL;       /* Ownership was passed to the segment */
         duration = 0;
-        title = NULL;
+        title = NULL;           /* Ownership was passed to the segment */
         discontinuity = FALSE;
         size = offset = -1;
         g_ptr_array_add (self->segments, file);
@@ -737,8 +738,12 @@ gst_hls_media_playlist_parse (gchar * data, const gchar * uri,
     data = g_utf8_next_char (end);      /* skip \n */
   }
 
+  /* Clean up date that wasn't freed / handed to a segment */
   g_free (current_key);
   current_key = NULL;
+  if (date_time)
+    g_date_time_unref (date_time);
+  g_free (title);
 
   g_free (input_data);