matroskademux: fix memory leak in check_subtitle_buffer
authorMatej Knopp <matej.knopp@gmail.com>
Fri, 26 Jul 2013 14:02:01 +0000 (16:02 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Fri, 26 Jul 2013 15:11:31 +0000 (17:11 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=704921

gst/matroska/matroska-demux.c

index fa70198..22d5427 100644 (file)
@@ -2977,6 +2977,7 @@ gst_matroska_demux_check_subtitle_buffer (GstElement * element,
   GstBuffer *newbuf;
   gchar *utf8;
   GstMapInfo map;
+  gboolean needs_unmap = TRUE;
 
   sub_stream = (GstMatroskaTrackSubtitleContext *) stream;
 
@@ -3027,10 +3028,10 @@ gst_matroska_demux_check_subtitle_buffer (GstElement * element,
     utf8 = g_strdup ("invalid subtitle");
 
   newbuf = gst_buffer_new_wrapped (utf8, strlen (utf8));
+  gst_buffer_unmap (*buf, &map);
   gst_buffer_copy_into (newbuf, *buf,
       GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_META,
       0, -1);
-  gst_buffer_unmap (*buf, &map);
   gst_buffer_unref (*buf);
 
   *buf = newbuf;
@@ -3047,16 +3048,20 @@ next:
       utf8 = g_markup_escape_text ((gchar *) map.data, map.size);
 
       newbuf = gst_buffer_new_wrapped (utf8, strlen (utf8));
+      gst_buffer_unmap (*buf, &map);
       gst_buffer_copy_into (newbuf, *buf,
           GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_FLAGS |
           GST_BUFFER_COPY_META, 0, -1);
-      gst_buffer_unmap (*buf, &map);
       gst_buffer_unref (*buf);
 
       *buf = newbuf;
+      needs_unmap = FALSE;
     }
   }
 
+  if (needs_unmap)
+    gst_buffer_unmap (*buf, &map);
+
   return GST_FLOW_OK;
 }