buffer: fix the _get_mapped function
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 3 Jul 2012 10:38:55 +0000 (12:38 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 3 Jul 2012 10:42:44 +0000 (12:42 +0200)
Fix the internal _get_mapped function. gst_memory_make_mapped() takes ownership
of the memory so we need to keep an additional ref until we are done.

gst/gstbuffer.c

index 7ebc4a7..925dd17 100644 (file)
@@ -785,18 +785,17 @@ _get_mapped (GstBuffer * buffer, guint idx, GstMapInfo * info,
 {
   GstMemory *mem, *mapped;
 
-  mem = GST_BUFFER_MEM_PTR (buffer, idx);
+  mem = gst_memory_ref (GST_BUFFER_MEM_PTR (buffer, idx));
 
   mapped = gst_memory_make_mapped (mem, info, flags);
-  if (!mapped)
-    return NULL;
 
-  if (mapped != mem) {
+  if (mapped && mapped != mem) {
+    /* new memory, replace old memory */
     GST_BUFFER_MEM_PTR (buffer, idx) = mapped;
-    gst_memory_unref (mem);
-    mem = mapped;
   }
-  return mem;
+  gst_memory_unref (mem);
+
+  return mapped;
 }
 
 /**