From 586b34436e889c57f3108e6160f20beb55e61cd7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 10 Mar 2017 10:13:05 +0100 Subject: [PATCH] buffer: handle gst_buffer_map failures --- libs/gst/check/gstharness.c | 9 ++++++--- plugins/elements/gstdownloadbuffer.c | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libs/gst/check/gstharness.c b/libs/gst/check/gstharness.c index f917786999..7a6d2aafd8 100644 --- a/libs/gst/check/gstharness.c +++ b/libs/gst/check/gstharness.c @@ -1741,9 +1741,12 @@ gst_harness_dump_to_file (GstHarness * h, const gchar * filename) while ((buf = g_async_queue_try_pop (priv->buffer_queue))) { GstMapInfo info; - gst_buffer_map (buf, &info, GST_MAP_READ); - fwrite (info.data, 1, info.size, fd); - gst_buffer_unmap (buf, &info); + if (gst_buffer_map (buf, &info, GST_MAP_READ)) { + fwrite (info.data, 1, info.size, fd); + gst_buffer_unmap (buf, &info); + } else { + GST_ERROR ("failed to map buffer %p", buf); + } gst_buffer_unref (buf); } diff --git a/plugins/elements/gstdownloadbuffer.c b/plugins/elements/gstdownloadbuffer.c index 36455ac246..1dea8a7e40 100644 --- a/plugins/elements/gstdownloadbuffer.c +++ b/plugins/elements/gstdownloadbuffer.c @@ -780,7 +780,8 @@ gst_download_buffer_read_buffer (GstDownloadBuffer * dlbuf, guint64 offset, else buf = *buffer; - gst_buffer_map (buf, &info, GST_MAP_WRITE); + if (!gst_buffer_map (buf, &info, GST_MAP_WRITE)) + goto map_failed; GST_DEBUG_OBJECT (dlbuf, "Reading %u bytes from %" G_GUINT64_FORMAT, length, offset); @@ -835,6 +836,14 @@ hit_eos: GST_DEBUG_OBJECT (dlbuf, "EOS hit"); return GST_FLOW_EOS; } +map_failed: + { + GST_ELEMENT_ERROR (dlbuf, RESOURCE, BUSY, + (_("Failed to map buffer.")), ("failed to map buffer in WRITE mode")); + if (*buffer == NULL) + gst_buffer_unref (buf); + return GST_FLOW_ERROR; + } out_flushing: { GST_DEBUG_OBJECT (dlbuf, "we are flushing"); @@ -1163,7 +1172,8 @@ gst_download_buffer_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GST_BUFFER_OFFSET (buffer), offset); } - gst_buffer_map (buffer, &info, GST_MAP_READ); + if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) + goto map_error; GST_DEBUG_OBJECT (dlbuf, "Writing %" G_GSIZE_FORMAT " bytes to %" G_GUINT64_FORMAT, info.size, offset); @@ -1248,6 +1258,14 @@ out_seeking: gst_buffer_unref (buffer); return GST_FLOW_OK; } +map_error: + { + GST_DOWNLOAD_BUFFER_MUTEX_UNLOCK (dlbuf); + gst_buffer_unref (buffer); + GST_ELEMENT_ERROR (dlbuf, RESOURCE, BUSY, + (_("Failed to map buffer.")), ("failed to map buffer in READ mode")); + return GST_FLOW_ERROR; + } write_error: { GST_DOWNLOAD_BUFFER_MUTEX_UNLOCK (dlbuf);