diff mbox

dmabuf: Make sure that memory is unmapped before releasing it

Message ID CA+M3ks7jijmL66DnWzGAYXbn=9SNNiTbVT3McxB4QeUmQ46aeg@mail.gmail.com
State Accepted
Headers show

Commit Message

Benjamin Gaignard May 19, 2013, 6:03 a.m. UTC
From e90e2bb8221b2671ecd2e19f48201b5871f3c6a5 Mon Sep 17 00:00:00 2001

From: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Date: Fri, 17 May 2013 07:16:08 +0000
Subject: dmabuf: Make sure that memory is unmapped before releasing it

Be sure that memory is unmapped before releasing it.
https://bugzilla.gnome.org/show_bug.cgi?id=700411
---
--
cgit v0.9.0.2-2-gbebe
diff mbox

Patch

diff --git a/gst-libs/gst/allocators/gstdmabuf.c
b/gst-libs/gst/allocators/gstdmabuf.c
index 95d26bb..4a95f47 100644
--- a/gst-libs/gst/allocators/gstdmabuf.c
+++ b/gst-libs/gst/allocators/gstdmabuf.c
@@ -62,17 +62,18 @@  GST_DEBUG_CATEGORY_STATIC (dmabuf_debug);
 #define GST_CAT_DEFAULT dmabuf_debug

 static void
-gst_dmabuf_allocator_free (GstAllocator * allocator, GstMemory * mem)
+gst_dmabuf_allocator_free (GstAllocator * allocator, GstMemory * gmem)
 {
-  GstDmaBufMemory *dbmem = (GstDmaBufMemory *) mem;
-
-  if (dbmem->data)
-    g_warning ("Freeing memory still mapped");
+  GstDmaBufMemory *mem = (GstDmaBufMemory *) gmem;

-  close (dbmem->fd);
-  g_mutex_clear (&dbmem->lock);
-  g_slice_free (GstDmaBufMemory, dbmem);
-  GST_DEBUG ("%p: freed", dbmem);
+  if (mem->data) {
+    g_warning (G_STRLOC ":%s: Freeing memory %p still mapped", G_STRFUNC, mem);
+    munmap ((void *) mem->data, mem->mmap_size);
+  }
+  close (mem->fd);
+  g_mutex_clear (&mem->lock);
+  g_slice_free (GstDmaBufMemory, mem);
+  GST_DEBUG ("%p: freed", mem);
 }

 static gpointer