From 0e096da4b486afce23559ec861305edd895128cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 27 Feb 2025 12:10:04 +0100 Subject: [PATCH] libcamera: request: addBuffer(): Do not destroy fence on failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Take the unique pointer to the `Fence` object by rvalue reference so that it is not destroyed if the function returns an error code and does not take ownership of the unique pointer. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Stefan Klug --- include/libcamera/request.h | 2 +- src/libcamera/request.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/libcamera/request.h b/include/libcamera/request.h index e214a9d1..0c5939f7 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -53,7 +53,7 @@ public: ControlList &metadata() { return *metadata_; } const BufferMap &buffers() const { return bufferMap_; } int addBuffer(const Stream *stream, FrameBuffer *buffer, - std::unique_ptr fence = nullptr); + std::unique_ptr &&fence = {}); FrameBuffer *findBuffer(const Stream *stream) const; uint32_t sequence() const; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 7f1e11e8..26bba8f2 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -452,7 +452,9 @@ void Request::reuse(ReuseFlag flags) * * When a valid Fence is provided to this function, \a fence is moved to \a * buffer and this Request will only be queued to the device once the - * fences of all its buffers have been correctly signalled. + * fences of all its buffers have been correctly signalled. Ownership of the + * fence will only be taken in case of success, otherwise the fence will + * be left unmodified. * * If the \a fence associated with \a buffer isn't signalled, the request will * fail after a timeout. The buffer will still contain the fence, which @@ -468,7 +470,7 @@ void Request::reuse(ReuseFlag flags) * \retval -EINVAL The buffer does not reference a valid Stream */ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, - std::unique_ptr fence) + std::unique_ptr &&fence) { if (!stream) { LOG(Request, Error) << "Invalid stream reference";