gstreamer: Be prepared when queueing request

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: 06bd05bece ("gstreamer: Use dedicated lock for request queues")
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Acked-by: Umang Jain <uajain@igalia.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2025-09-09 14:17:57 +02:00
parent fa22b4ffef
commit 65db93f8f4

View File

@@ -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));
}