[Mesa-dev] [PATCH kmscube 1/2] gst-decoder.c: Only gst_is_dmabuf_memory() once

Carlos Rafael Giani dv at pseudoterminal.org
Mon Apr 10 14:03:35 UTC 2017


This prevents potential segfaults in case the buffer was merged and the
mem pointer is then no longer valid

Signed-off-by: Carlos Rafael Giani <dv at pseudoterminal.org>
---
 gst-decoder.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gst-decoder.c b/gst-decoder.c
index e59148a..cc5c3b2 100644
--- a/gst-decoder.c
+++ b/gst-decoder.c
@@ -360,6 +360,7 @@ buffer_to_image(struct decoder *dec, GstBuffer *buf)
 	guint nplanes = GST_VIDEO_INFO_N_PLANES(&(dec->info));
 	guint i;
 	guint width, height;
+	gboolean is_dmabuf_mem;
 	GstMemory *mem;
 	int dmabuf_fd = -1;
 
@@ -379,10 +380,14 @@ buffer_to_image(struct decoder *dec, GstBuffer *buf)
 		EGL_DMA_BUF_PLANE2_PITCH_EXT,
 	};
 
+	/* Query gst_is_dmabuf_memory() here, since the gstmemory
+	 * block might get merged below by gst_buffer_map(), meaning
+	 * that the mem pointer would become invalid */
 	mem = gst_buffer_peek_memory(buf, 0);
+	is_dmabuf_mem = gst_is_dmabuf_memory(mem);
 
 	if (nmems > 1) {
-		if (gst_is_dmabuf_memory(mem)) {
+		if (is_dmabuf_mem) {
 			/* this case currently is not defined */
 
 			GST_FIXME("gstbuffers with multiple memory blocks and DMABUF "
@@ -395,7 +400,7 @@ buffer_to_image(struct decoder *dec, GstBuffer *buf)
 		 */
 	}
 
-	if (gst_is_dmabuf_memory(mem)) {
+	if (is_dmabuf_mem) {
 		dmabuf_fd = dup(gst_dmabuf_memory_get_fd(mem));
 	} else {
 		GstMapInfo map_info;
@@ -447,7 +452,7 @@ buffer_to_image(struct decoder *dec, GstBuffer *buf)
 		printf("GStreamer video stream information:\n");
 		printf("  size: %u x %u pixel\n", width, height);
 		printf("  pixel format: %s  number of planes: %u\n", pixfmt_str, nplanes);
-		printf("  can use zero-copy: %s\n", yesno(gst_is_dmabuf_memory(mem)));
+		printf("  can use zero-copy: %s\n", yesno(is_dmabuf_mem));
 		printf("  video meta found: %s\n", yesno(meta != NULL));
 		printf("===================================\n");
 	}
-- 
2.7.4



More information about the mesa-dev mailing list