[{"id":34412,"web_url":"https://patchwork.libcamera.org/comment/34412/","msgid":"<0db86d26-e97c-4312-ad24-c3df4d267f52@ideasonboard.com>","date":"2025-06-04T13:36:34","subject":"Re: [PATCH v2 5/7] gstreamer: Fix leak of GstQuery and GstBufferPool\n\tin error path","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n\n2025. 06. 04. 15:07 keltezéssel, Laurent Pinchart írta:\n> The gst_libcamera_create_video_pool() function leaks a GstQuery instance\n> and a GstBufferPool instance in an error path. Fix the leaks with\n> g_autoptr().\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>   src/gstreamer/gstlibcamerasrc.cpp | 7 +++----\n>   1 file changed, 3 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 9c0ee491ab63..0be64dd836ca 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -541,9 +541,9 @@ static std::tuple<GstBufferPool *, int>\n>   gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,\n>   \t\t\t\tGstCaps *caps, const GstVideoInfo *info)\n>   {\n> -\tGstQuery *query = NULL;\n> +\tg_autoptr(GstQuery) query = NULL;\n> +\tg_autoptr(GstBufferPool) pool = NULL;\n>   \tconst gboolean need_pool = true;\n> -\tGstBufferPool *pool = NULL;\n>   \n>   \t/*\n>   \t * Get the peer allocation hints to check if it supports the meta API.\n> @@ -587,8 +587,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,\n>   \t\treturn { NULL, -EINVAL };\n>   \t}\n>   \n> -\tgst_query_unref(query);\n> -\treturn { pool, 0 };\n> +\treturn { reinterpret_cast<GstBufferPool *>(g_steal_pointer(&pool)), 0 };\n\n`std::exchange(pool, nullptr)` ? I used that in https://patchwork.libcamera.org/patch/22455/\nbecause `g_steal_pointer()` only preserves the type since glib 2.68.\n\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\nRegards,\nBarnabás Pőcze\n\n\n>   }\n>   \n>   /* Must be called with stream_lock held. */","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9801BC31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  4 Jun 2025 13:36:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E57B68DBD;\n\tWed,  4 Jun 2025 15:36:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6234B68DA8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 Jun 2025 15:36:46 +0200 (CEST)","from [192.168.33.16] (185.182.214.22.nat.pool.zt.hu\n\t[185.182.214.22])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DDC4978C;\n\tWed,  4 Jun 2025 15:36:42 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"p0UYKBdj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1749044203;\n\tbh=ZyPv+/RmVn7JSw2/ovhhgKWt13fhnSDGnORF2SP/UxU=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=p0UYKBdjBMU5zzuAa75vvzEBrrkisHAGjjEh3r2/gTMHQ21O5fVM/4ED0yP22OKP1\n\ttIEZm6y+hMmNEPWc3QIcVXlH00KEkV71kRUu+Rf5AIjC6T2mLWjsf5TY79K5v/ud1k\n\tsANeeh+CBcZms3KIKR1mI1sIgK7DaSeSmaCMVNCU=","Message-ID":"<0db86d26-e97c-4312-ad24-c3df4d267f52@ideasonboard.com>","Date":"Wed, 4 Jun 2025 15:36:34 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 5/7] gstreamer: Fix leak of GstQuery and GstBufferPool\n\tin error path","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"Hou Qi <qi.hou@nxp.com>,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","References":"<20250604130741.9228-1-laurent.pinchart@ideasonboard.com>\n\t<20250604130741.9228-6-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250604130741.9228-6-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34414,"web_url":"https://patchwork.libcamera.org/comment/34414/","msgid":"<20250604134152.GF3755@pendragon.ideasonboard.com>","date":"2025-06-04T13:41:52","subject":"Re: [PATCH v2 5/7] gstreamer: Fix leak of GstQuery and GstBufferPool\n\tin error path","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Jun 04, 2025 at 03:36:34PM +0200, Barnabás Pőcze wrote:\n> 2025. 06. 04. 15:07 keltezéssel, Laurent Pinchart írta:\n> > The gst_libcamera_create_video_pool() function leaks a GstQuery instance\n> > and a GstBufferPool instance in an error path. Fix the leaks with\n> > g_autoptr().\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >   src/gstreamer/gstlibcamerasrc.cpp | 7 +++----\n> >   1 file changed, 3 insertions(+), 4 deletions(-)\n> > \n> > diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> > index 9c0ee491ab63..0be64dd836ca 100644\n> > --- a/src/gstreamer/gstlibcamerasrc.cpp\n> > +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> > @@ -541,9 +541,9 @@ static std::tuple<GstBufferPool *, int>\n> >   gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,\n> >   \t\t\t\tGstCaps *caps, const GstVideoInfo *info)\n> >   {\n> > -\tGstQuery *query = NULL;\n> > +\tg_autoptr(GstQuery) query = NULL;\n> > +\tg_autoptr(GstBufferPool) pool = NULL;\n> >   \tconst gboolean need_pool = true;\n> > -\tGstBufferPool *pool = NULL;\n> >   \n> >   \t/*\n> >   \t * Get the peer allocation hints to check if it supports the meta API.\n> > @@ -587,8 +587,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad,\n> >   \t\treturn { NULL, -EINVAL };\n> >   \t}\n> >   \n> > -\tgst_query_unref(query);\n> > -\treturn { pool, 0 };\n> > +\treturn { reinterpret_cast<GstBufferPool *>(g_steal_pointer(&pool)), 0 };\n> \n> `std::exchange(pool, nullptr)` ? I used that in https://patchwork.libcamera.org/patch/22455/\n> because `g_steal_pointer()` only preserves the type since glib 2.68.\n\nGood idea. I'll use that.\n\n> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> \n> >   }\n> >   \n> >   /* Must be called with stream_lock held. */","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E8946C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  4 Jun 2025 13:42:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E181068DBD;\n\tWed,  4 Jun 2025 15:42:03 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E15AA68DA8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 Jun 2025 15:42:02 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 995F078C;\n\tWed,  4 Jun 2025 15:41:59 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Yh71gg/K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1749044519;\n\tbh=Of1TCH9ylQVySyrsL+KORe9OCE/iiBG7vZrtA054dxs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Yh71gg/KBBGnLkmGQnJ6PLu4K7xVlJVRQl8d1xgWwvEktfuMpkugqI/BatxTb0z0S\n\tlHyffvNSc/VLxG74h632KVV4N8jHK8IMgeDi/VXq7xEKkp4yX8XJKe+CRjmjH4Sq3h\n\t1161uszjnbM4qhCRrFbyb37WbhCBtT4DtvbAhyxQ=","Date":"Wed, 4 Jun 2025 16:41:52 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, Hou Qi <qi.hou@nxp.com>,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Subject":"Re: [PATCH v2 5/7] gstreamer: Fix leak of GstQuery and GstBufferPool\n\tin error path","Message-ID":"<20250604134152.GF3755@pendragon.ideasonboard.com>","References":"<20250604130741.9228-1-laurent.pinchart@ideasonboard.com>\n\t<20250604130741.9228-6-laurent.pinchart@ideasonboard.com>\n\t<0db86d26-e97c-4312-ad24-c3df4d267f52@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<0db86d26-e97c-4312-ad24-c3df4d267f52@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]