[0.11] gstreamer: memory: handle -1 size in unmap

Wim Taymans wtay at kemper.freedesktop.org
Thu Jan 5 22:03:37 PST 2012


Module: gstreamer
Branch: 0.11
Commit: 960c580ae224f2537faf914a8c39fb0881acbd49
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=960c580ae224f2537faf914a8c39fb0881acbd49

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Fri Jan  6 07:02:36 2012 +0100

memory: handle -1 size in unmap

handle -1 in unmap correctly when the offset is modified.

---

 gst/gstmemory.c             |    8 ++++++--
 tests/check/gst/gstmemory.c |   16 ++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gst/gstmemory.c b/gst/gstmemory.c
index 923bd2f..b062180 100644
--- a/gst/gstmemory.c
+++ b/gst/gstmemory.c
@@ -217,8 +217,12 @@ _default_mem_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
   g_return_val_if_fail ((guint8 *) data >= mem->data
       && (guint8 *) data < mem->data + mem->maxsize, FALSE);
 
-  if (mem->data + mem->offset != data)
-    mem->offset = (guint8 *) data - mem->data;
+  if (mem->data + mem->offset != data) {
+    gsize newoffset = (guint8 *) data - mem->data;
+    if (size == -1)
+      size = mem->offset + mem->size - newoffset;
+    mem->offset = newoffset;
+  }
 
   if (size != -1) {
     g_return_val_if_fail (mem->offset + size <= mem->maxsize, FALSE);
diff --git a/tests/check/gst/gstmemory.c b/tests/check/gst/gstmemory.c
index 1cc4f9b..d6861a3 100644
--- a/tests/check/gst/gstmemory.c
+++ b/tests/check/gst/gstmemory.c
@@ -527,6 +527,22 @@ GST_START_TEST (test_map_resize)
   fail_unless (offset == 0);
   fail_unless (maxalloc >= 100);
 
+  data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
+  gst_memory_unmap (mem, (guint8 *) data + 1, -1);
+
+  size = gst_memory_get_sizes (mem, &offset, &maxalloc);
+  fail_unless (size == 99);
+  fail_unless (offset == 1);
+  fail_unless (maxalloc >= 100);
+
+  data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
+  gst_memory_unmap (mem, (guint8 *) data - 1, -1);
+
+  size = gst_memory_get_sizes (mem, &offset, &maxalloc);
+  fail_unless (size == 100);
+  fail_unless (offset == 0);
+  fail_unless (maxalloc >= 100);
+
   gst_memory_unref (mem);
 }
 



More information about the gstreamer-commits mailing list