From 65db93f8f4d2eb7ca31a0e9ddbcbc3cc6b9c8b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 9 Sep 2025 14:17:57 +0200 Subject: [PATCH] gstreamer: Be prepared when queueing request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The moment execution enters `Camera::queueRequest()`, an application must be prepared to receive the corresponding `requestCompleted` signal. However, the gstreamer element is currently not prepared: it queues the request, takes a lock, then inserts into a list. If the request completion handler acquires the lock right after queueing the request, then it will not find the expected object in the list. Even potentially encountering an empty list, running into undefined behaviour when trying to pop the first element from it. Fix that by queueing the request while the lock is held. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/238 Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/306 Fixes: 06bd05beced313 ("gstreamer: Use dedicated lock for request queues") Signed-off-by: Barnabás Pőcze Acked-by: Umang Jain Reviewed-by: Kieran Bingham --- src/gstreamer/gstlibcamerasrc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 391b228d..a7241e9b 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -208,10 +208,10 @@ int GstLibcameraSrcState::queueRequest() } GST_TRACE_OBJECT(src_, "Requesting buffers"); - cam_->queueRequest(wrap->request_.get()); { GLibLocker locker(&lock_); + cam_->queueRequest(wrap->request_.get()); queuedRequests_.push(std::move(wrap)); }