[libcamera-devel,1/3] lc-compliance: simple_capture: Fix Request reuse
diff mbox series

Message ID 20221213093802.704177-2-paul.elder@ideasonboard.com
State New
Headers show
  • lc-compliance: Fix SimpleCapture test
Related show

Commit Message

Paul Elder Dec. 13, 2022, 9:38 a.m. UTC
In the balanced simple capture test, in the request completion handler,
the Request is marked for reuse *before* checking (based on the
queueCount_) if it should actually be queued to the Camera. This causes
the last Request to end up being marked for reuse and then *not* get
queued to the Camera.

The consequence of this is that a buffer is assigned to the Request, so
that it must be canceled when the Request is destroyed. Additionally,
since the Request was not queued to the Camera, it doesn't get completed
at all by the Camera. Thus the buffer is deallocated by
SimpleCapture::stop(), and after SimpleCaptureBalanced::capture() exits,
the Request is destroyed and tries to cancel the deallocated buffer,
causing the segfault.

Fix this by reordering marking the Request for reuse so that it happens
if and only if the Request wil be queued to the Camera.

Fixes: https://bugs.libcamera.org/show_bug.cgi?id=171
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
 src/apps/lc-compliance/simple_capture.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff mbox series

diff --git a/src/apps/lc-compliance/simple_capture.cpp b/src/apps/lc-compliance/simple_capture.cpp
index cf4d7cf3..4a05b919 100644
--- a/src/apps/lc-compliance/simple_capture.cpp
+++ b/src/apps/lc-compliance/simple_capture.cpp
@@ -122,6 +122,7 @@  int SimpleCaptureBalanced::queueRequest(Request *request)
 	if (queueCount_ > captureLimit_)
 		return 0;
+	request->reuse(Request::ReuseBuffers);
 	return camera_->queueRequest(request);
@@ -133,7 +134,6 @@  void SimpleCaptureBalanced::requestComplete(Request *request)
-	request->reuse(Request::ReuseBuffers);
 	if (queueRequest(request))