From 772b06bd8c7e989c7fc041e7ad982cbec87e0635 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 22 May 2025 11:47:29 +0200 Subject: [PATCH] gstreamer: Fix leak of GstQuery and GstBufferPool in error path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gst_libcamera_create_video_pool() function leaks a GstQuery instance and a GstBufferPool instance in an error path. Fix the leaks with g_autoptr(). Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- src/gstreamer/gstlibcamerasrc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 9cc8d9e3..05b47ece 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -540,9 +541,9 @@ static std::tuple gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, GstCaps *caps, const GstVideoInfo *info) { - GstQuery *query = NULL; + g_autoptr(GstQuery) query = NULL; + g_autoptr(GstBufferPool) pool = NULL; const gboolean need_pool = true; - GstBufferPool *pool = NULL; /* * Get the peer allocation hints to check if it supports the meta API. @@ -586,8 +587,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, return { NULL, -EINVAL }; } - gst_query_unref(query); - return { pool, 0 }; + return { std::exchange(pool, nullptr), 0 }; } /* Must be called with stream_lock held. */