[libcamera-devel] [PATCH 2/2] gst: pool: Fix GstBuffer leak on error

Nicolas Dufresne nicolas at ndufresne.ca
Thu Mar 11 21:52:55 CET 2021


From: Nicolas Dufresne <nicolas.dufresne at collabora.com>

We borrowed a GstBuffer from the pool, if preparing the buffer failed,
we need to push it back to avoid leaking it.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
---
 src/gstreamer/gstlibcamerapool.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/gstreamer/gstlibcamerapool.cpp b/src/gstreamer/gstlibcamerapool.cpp
index 62db184f..1fde4213 100644
--- a/src/gstreamer/gstlibcamerapool.cpp
+++ b/src/gstreamer/gstlibcamerapool.cpp
@@ -40,8 +40,10 @@ gst_libcamera_pool_acquire_buffer(GstBufferPool *pool, GstBuffer **buffer,
 	if (!buf)
 		return GST_FLOW_ERROR;
 
-	if (!gst_libcamera_allocator_prepare_buffer(self->allocator, self->stream, buf))
+	if (!gst_libcamera_allocator_prepare_buffer(self->allocator, self->stream, buf)) {
+		gst_atomic_queue_push(self->queue, buf);
 		return GST_FLOW_ERROR;
+	}
 
 	*buffer = buf;
 	return GST_FLOW_OK;
-- 
2.29.2



More information about the libcamera-devel mailing list