memory/buffer: Initialise GstMapInfo to zeroes if mapping fails

This should allow for more meaningful errors. Dereferencing NULL
is more useful information than dereferencing a random address
happened to be on the stack.
This commit is contained in:
Sebastian Dröge 2014-04-16 19:49:56 +02:00
parent dded0a4bb6
commit 81f9a22228
2 changed files with 5 additions and 4 deletions

View file

@ -1583,21 +1583,20 @@ not_writable:
{ {
GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer"); GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer");
g_critical ("write map requested on non-writable buffer"); g_critical ("write map requested on non-writable buffer");
memset (info, 0, sizeof (GstMapInfo));
return FALSE; return FALSE;
} }
no_memory: no_memory:
{ {
/* empty buffer, we need to return NULL */ /* empty buffer, we need to return NULL */
GST_DEBUG_OBJECT (buffer, "can't get buffer memory"); GST_DEBUG_OBJECT (buffer, "can't get buffer memory");
info->memory = NULL; memset (info, 0, sizeof (GstMapInfo));
info->data = NULL;
info->size = 0;
info->maxsize = 0;
return TRUE; return TRUE;
} }
cannot_map: cannot_map:
{ {
GST_DEBUG_OBJECT (buffer, "cannot map memory"); GST_DEBUG_OBJECT (buffer, "cannot map memory");
memset (info, 0, sizeof (GstMapInfo));
return FALSE; return FALSE;
} }
} }

View file

@ -310,6 +310,7 @@ gst_memory_map (GstMemory * mem, GstMapInfo * info, GstMapFlags flags)
lock_failed: lock_failed:
{ {
GST_CAT_DEBUG (GST_CAT_MEMORY, "mem %p: lock %d failed", mem, flags); GST_CAT_DEBUG (GST_CAT_MEMORY, "mem %p: lock %d failed", mem, flags);
memset (info, 0, sizeof (GstMapInfo));
return FALSE; return FALSE;
} }
error: error:
@ -317,6 +318,7 @@ error:
/* something went wrong, restore the orginal state again */ /* something went wrong, restore the orginal state again */
GST_CAT_ERROR (GST_CAT_MEMORY, "mem %p: subclass map failed", mem); GST_CAT_ERROR (GST_CAT_MEMORY, "mem %p: subclass map failed", mem);
gst_memory_unlock (mem, (GstLockFlags) flags); gst_memory_unlock (mem, (GstLockFlags) flags);
memset (info, 0, sizeof (GstMapInfo));
return FALSE; return FALSE;
} }
} }