v4l2bufferpool: Fix race condition between qbuf and pool streamoff

There is a chance that pool->buffers[index] sets BUFFER_STATE_QUEUED, but
it has not been queued yet which makes pool->buffers[index] still NULL.
At this time, if pool_streamff release all buffers with BUFFER_STATE_QUEUED
state regardless of whether the buffer is NULL or not, it will cause segfault.

To fix this, also check buffer when streamoff release buffer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1842>
This commit is contained in:
Hou Qi 2022-03-03 13:47:05 +08:00 committed by GStreamer Marge Bot
parent 52c0763042
commit fa6f34d595

View file

@ -744,7 +744,7 @@ gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool)
for (i = 0; i < VIDEO_MAX_FRAME; i++) {
gint old_buffer_state =
g_atomic_int_and (&pool->buffer_state[i], ~BUFFER_STATE_QUEUED);
if (old_buffer_state & BUFFER_STATE_QUEUED) {
if ((old_buffer_state & BUFFER_STATE_QUEUED) && pool->buffers[i]) {
GstBuffer *buffer = pool->buffers[i];
GstBufferPool *bpool = GST_BUFFER_POOL (pool);