dmabuf: fix memory initialization
authorMichael Olbrich <m.olbrich@pengutronix.de>
Fri, 3 May 2013 09:12:04 +0000 (11:12 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 3 May 2013 11:11:14 +0000 (13:11 +0200)
Without this the shared memory is broken

https://bugzilla.gnome.org/show_bug.cgi?id=699565

gst-libs/gst/allocators/gstdmabuf.c

index 3c92dda..9700bc6 100644 (file)
@@ -153,12 +153,15 @@ gst_dmabuf_mem_share (GstMemory * gmem, gssize offset, gssize size)
   if (size == -1)
     size = mem->mem.size - offset;
 
-  sub = g_slice_new (GstDmaBufMemory);
+  sub = g_slice_new0 (GstDmaBufMemory);
   /* the shared memory is always readonly */
   gst_memory_init (GST_MEMORY_CAST (sub), GST_MINI_OBJECT_FLAGS (parent) |
       GST_MINI_OBJECT_FLAG_LOCK_READONLY, mem->mem.allocator, parent,
       mem->mem.maxsize, mem->mem.align, mem->mem.offset + offset, size);
 
+  sub->fd = dup (mem->fd);
+  g_mutex_init (&sub->lock);
+
   return GST_MEMORY_CAST (sub);
 }
 
@@ -268,14 +271,11 @@ gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size)
 
   GST_DEBUG ("alloc from allocator %p", allocator);
 
-  mem = g_slice_new (GstDmaBufMemory);
+  mem = g_slice_new0 (GstDmaBufMemory);
 
   gst_memory_init (GST_MEMORY_CAST (mem), 0, allocator, NULL, size, 0, 0, 0);
 
   mem->fd = fd;
-  mem->data = NULL;
-  mem->mmapping_flags = 0;
-  mem->mmap_count = 0;
   g_mutex_init (&mem->lock);
 
   GST_DEBUG ("%p: fd: %d size %" G_GSIZE_FORMAT, mem, mem->fd,