Commit 960c580a authored by Wim Taymans's avatar Wim Taymans

memory: handle -1 size in unmap

handle -1 in unmap correctly when the offset is modified.
parent e4a58ec7
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment