summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMarcin Lewandowski <marcin@radiokit.org>2016-07-07 20:40:22 +0200
committerOlivier CrĂȘte <olivier.crete@collabora.com>2017-12-19 17:32:19 -0500
commit9a128603c96b0a9d55fe2b22542b8a207d2d61ee (patch)
tree49b7fbdf53c6cbc6cc880ab3c5fc0fcd5de6e15b /sys
parentf4b9d8c2992cce0004f17036bb62813b3a9bd1de (diff)
downloadgstreamer-plugins-bad-9a128603c96b0a9d55fe2b22542b8a207d2d61ee.tar.gz
smhsink: Check return values of functions working on memory
https://bugzilla.gnome.org/show_bug.cgi?id=768530
Diffstat (limited to 'sys')
-rw-r--r--sys/shm/gstshmsink.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/sys/shm/gstshmsink.c b/sys/shm/gstshmsink.c
index 1e77c13df..c67cc50d6 100644
--- a/sys/shm/gstshmsink.c
+++ b/sys/shm/gstshmsink.c
@@ -698,13 +698,11 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
if (need_new_memory) {
if (gst_buffer_get_size (buf) > sp_writer_get_max_buf_size (self->pipe)) {
gsize area_size = sp_writer_get_max_buf_size (self->pipe);
- GST_OBJECT_UNLOCK (self);
- GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT,
- ("Shared memory area is too small"),
+ GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT, (NULL),
("Shared memory area of size %" G_GSIZE_FORMAT " is smaller than"
"buffer of size %" G_GSIZE_FORMAT, area_size,
gst_buffer_get_size (buf)));
- return GST_FLOW_ERROR;
+ goto error;
}
while ((memory =
@@ -724,24 +722,48 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
}
}
- gst_memory_map (memory, &map, GST_MAP_WRITE);
- gst_buffer_extract (buf, 0, map.data, map.size);
+ if (!gst_memory_map (memory, &map, GST_MAP_WRITE)) {
+ GST_ELEMENT_ERROR (self, STREAM, FAILED,
+ (NULL), ("Failed to map memory"));
+ goto error;
+ }
+
+ GST_DEBUG_OBJECT (self,
+ "Copying %" G_GSIZE_FORMAT " bytes into map of size %" G_GSIZE_FORMAT
+ " bytes.", gst_buffer_get_size (buf), map.size);
+ gsize written_bytes = gst_buffer_extract (buf, 0, map.data, map.size);
+ GST_DEBUG_OBJECT (self, "Copied %" G_GSIZE_FORMAT " bytes.", written_bytes);
gst_memory_unmap (memory, &map);
sendbuf = gst_buffer_new ();
- gst_buffer_copy_into (sendbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1);
+ if (!gst_buffer_copy_into (sendbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1)) {
+ GST_ELEMENT_ERROR (self, STREAM, FAILED,
+ (NULL), ("Failed to copy data into send buffer"));
+ gst_buffer_unref (sendbuf);
+ goto error;
+ }
gst_buffer_append_memory (sendbuf, memory);
} else {
sendbuf = gst_buffer_ref (buf);
}
- gst_buffer_map (sendbuf, &map, GST_MAP_READ);
+ if (!gst_buffer_map (sendbuf, &map, GST_MAP_READ)) {
+ GST_ELEMENT_ERROR (self, STREAM, FAILED,
+ (NULL), ("Failed to map data into send buffer"));
+ goto error;
+ }
+
/* Make the memory readonly as of now as we've sent it to the other side
* We know it's not mapped for writing anywhere as we just mapped it for
* reading
*/
-
rv = sp_writer_send_buf (self->pipe, (char *) map.data, map.size, sendbuf);
+ if (rv == -1) {
+ GST_ELEMENT_ERROR (self, STREAM, FAILED,
+ (NULL), ("Failed to send data over SHM"));
+ gst_buffer_unmap (sendbuf, &map);
+ goto error;
+ }
gst_buffer_unmap (sendbuf, &map);
@@ -750,19 +772,17 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
if (rv == 0) {
GST_DEBUG_OBJECT (self, "No clients connected, unreffing buffer");
gst_buffer_unref (sendbuf);
- } else if (rv == -1) {
- GST_ELEMENT_ERROR (self, STREAM, FAILED, ("Invalid allocated buffer"),
- ("The shmpipe library rejects our buffer, this is a bug"));
- ret = GST_FLOW_ERROR;
}
- /* If we allocated our own memory, then unmap it */
-
return ret;
flushing:
GST_OBJECT_UNLOCK (self);
return GST_FLOW_FLUSHING;
+
+error:
+ GST_OBJECT_UNLOCK (self);
+ return GST_FLOW_ERROR;
}
static void
@@ -790,8 +810,9 @@ pollthread_func (gpointer data)
} while (rv < 0 && errno == EINTR);
if (rv < 0) {
- GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed waiting on fd activity"),
- ("gst_poll_wait returned %d, errno: %d", rv, errno));
+ GST_ELEMENT_ERROR (self, RESOURCE, READ,
+ ("Failed waiting on fd activity"),
+ ("gst_poll_wait returned %d, errno: %d", rv, errno));
return NULL;
}