memory: fix maxsize after align
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 14 Mar 2012 23:23:57 +0000 (00:23 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 15 Mar 2012 12:42:17 +0000 (13:42 +0100)
when we align the data pointer, make sure to update the maxsize.
Add some more debug

gst/gstmemory.c

index 726c23d..22b35f5 100644 (file)
@@ -146,7 +146,9 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
   mem->user_data = user_data;
   mem->notify = notify;
 
-  GST_CAT_DEBUG (GST_CAT_MEMORY, "new memory %p", mem);
+  GST_CAT_DEBUG (GST_CAT_MEMORY, "new memory %p, maxsize:%" G_GSIZE_FORMAT
+      " offset:%" G_GSIZE_FORMAT " size:%" G_GSIZE_FORMAT, mem, maxsize,
+      offset, size);
 }
 
 /* create a new memory block that manages the given memory */
@@ -189,8 +191,11 @@ _default_mem_new_block (GstMemoryFlags flags, gsize maxsize, gsize align,
 
   data = (guint8 *) mem + sizeof (GstMemoryDefault);
 
-  if ((aoffset = ((guintptr) data & align)))
-    data += (align + 1) - aoffset;
+  if ((aoffset = ((guintptr) data & align))) {
+    aoffset = (align + 1) - aoffset;
+    data += aoffset;
+    maxsize -= aoffset;
+  }
 
   if (offset && (flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
     memset (data, 0, offset);