From 960c580ae224f2537faf914a8c39fb0881acbd49 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 Jan 2012 07:02:36 +0100 Subject: [PATCH] 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 923bd2f55a..b062180da6 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 1cc4f9bf39..d6861a3151 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); } -- 2.34.1