memory/buffer: Initialise GstMapInfo to zeroes if mapping fails
authorSebastian Dröge <sebastian@centricular.com>
Wed, 16 Apr 2014 17:49:56 +0000 (19:49 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 16 Apr 2014 17:49:56 +0000 (19:49 +0200)
This should allow for more meaningful errors. Dereferencing NULL
is more useful information than dereferencing a random address
happened to be on the stack.

gst/gstbuffer.c
gst/gstmemory.c

index 1cea700..d727bb3 100644 (file)
@@ -1583,21 +1583,20 @@ not_writable:
   {
     GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer");
     g_critical ("write map requested on non-writable buffer");
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 no_memory:
   {
     /* empty buffer, we need to return NULL */
     GST_DEBUG_OBJECT (buffer, "can't get buffer memory");
-    info->memory = NULL;
-    info->data = NULL;
-    info->size = 0;
-    info->maxsize = 0;
+    memset (info, 0, sizeof (GstMapInfo));
     return TRUE;
   }
 cannot_map:
   {
     GST_DEBUG_OBJECT (buffer, "cannot map memory");
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 }
index 586da2f..dddabaa 100644 (file)
@@ -310,6 +310,7 @@ gst_memory_map (GstMemory * mem, GstMapInfo * info, GstMapFlags flags)
 lock_failed:
   {
     GST_CAT_DEBUG (GST_CAT_MEMORY, "mem %p: lock %d failed", mem, flags);
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 error:
@@ -317,6 +318,7 @@ error:
     /* something went wrong, restore the orginal state again */
     GST_CAT_ERROR (GST_CAT_MEMORY, "mem %p: subclass map failed", mem);
     gst_memory_unlock (mem, (GstLockFlags) flags);
+    memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
 }