From 81f9a22228e5158b89e4aded38b4966a7b784b8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 16 Apr 2014 19:49:56 +0200 Subject: [PATCH] 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. --- gst/gstbuffer.c | 7 +++---- gst/gstmemory.c | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 1cea700..d727bb3 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -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; } } diff --git a/gst/gstmemory.c b/gst/gstmemory.c index 586da2f..dddabaa 100644 --- a/gst/gstmemory.c +++ b/gst/gstmemory.c @@ -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; } } -- 2.7.4