[libcamera-devel,2/2] gst: pool: Fix GstBuffer leak on error
diff mbox series

Message ID 20210311205255.741985-3-nicolas@ndufresne.ca
State Accepted
Commit 6795ffe67f3318e474ee14141e5b394b0e5d2d85
Headers show
Series
  • GStreamer Fixes
Related show

Commit Message

Nicolas Dufresne March 11, 2021, 8:52 p.m. UTC
From: Nicolas Dufresne <nicolas.dufresne@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@collabora.com>
---
 src/gstreamer/gstlibcamerapool.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart March 11, 2021, 10:46 p.m. UTC | #1
Hi Nicolas,

Thank you for the patch.

On Thu, Mar 11, 2021 at 03:52:55PM -0500, Nicolas Dufresne wrote:
> From: Nicolas Dufresne <nicolas.dufresne@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@collabora.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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;
Umang Jain March 12, 2021, 5:08 a.m. UTC | #2
Hi Nicolas,

On 3/12/21 2:22 AM, Nicolas Dufresne wrote:
> From: Nicolas Dufresne <nicolas.dufresne@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@collabora.com>
Reviewed-by: Umang Jain <email@uajain.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;

Patch
diff mbox series

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;