From f7c682f80217c7ef70a4a2f0c2e4945ce403657a Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 7 Jan 2015 18:48:58 -0500 Subject: [PATCH] v4l2allocator: Add protection against driver bug v4l2loopback driver has a this nasty bug that if the queue is larger then 2 buffers, it returns random index on dqbuf. So far we assumed that the index was always right, which would lead to memory being unref twice, and eventually crash. --- sys/v4l2/gstv4l2allocator.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/v4l2/gstv4l2allocator.c b/sys/v4l2/gstv4l2allocator.c index 97f8752df8..76986ba58f 100644 --- a/sys/v4l2/gstv4l2allocator.c +++ b/sys/v4l2/gstv4l2allocator.c @@ -1305,6 +1305,13 @@ gst_v4l2_allocator_dqbuf (GstV4l2Allocator * allocator) goto error; group = allocator->groups[buffer.index]; + + if (!IS_QUEUED (group->buffer)) { + GST_ERROR_OBJECT (allocator, + "buffer %i was not queued, this indicate a driver bug.", buffer.index); + return NULL; + } + group->buffer = buffer; GST_LOG_OBJECT (allocator, "dequeued buffer %i (flags 0x%X)", buffer.index,