{"id":22455,"url":"https://patchwork.libcamera.org/api/patches/22455/?format=json","web_url":"https://patchwork.libcamera.org/patch/22455/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250106100613.493108-2-pobrn@protonmail.com>","date":"2025-01-06T10:06:22","name":"[v3,2/2] gstreamer: allocator: gst_libcamera_allocator_new(): Fix memory leak","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3308ef1d0bfe3a0639536789aff67da2a5738d6e","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22455/mbox/","series":[{"id":4930,"url":"https://patchwork.libcamera.org/api/series/4930/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4930","date":"2025-01-06T10:06:16","name":"[v3,1/2] gstreamer: allocator: gst_libcamera_allocator_new(): Recognize errors","version":3,"mbox":"https://patchwork.libcamera.org/series/4930/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22455/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22455/checks/","tags":{},"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 9254AC32D4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Jan 2025 10:06:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 06506684EA;\n\tMon,  6 Jan 2025 11:06:30 +0100 (CET)","from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 50543684E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Jan 2025 11:06:28 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"KhuGRfEI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1736157987; x=1736417187;\n\tbh=RUYbbDRZpY+InpodoobX2qRjgDsVnbWFkNnwOoqzK9I=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=KhuGRfEI1dK6gcb6SmnodryzFBXnnvKvqBOosXCBUPPBGHcjoK+CT7Nz35rBRYXEL\n\tlJ55ZqJ9UjuLb8u5WraSRy5loqXBKT8tl5tmUbiCFRp9l3fw7+w5DR5r/ZBXgKQ4hK\n\tvrlg40HweWPnFR3UhhJ+Jyurs4Xov1Btv4mNi6HEkM9V4etzXAlixCmI+iQjR8FJ6H\n\taWJFJ074CMAlGaR+AyHcpK+jz6SdQjiPeBPPs89QLg2So4PwNBG+9cq8GjCYU7dUq3\n\t3B24/jDq38ALVvOJt2hnE8YJA8cZcI5afiDEa9G1YWnD1xJC3ien4NIdd31sHq/PxS\n\tvzKq2J9fPkn0w==","Date":"Mon, 06 Jan 2025 10:06:22 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"[PATCH v3 2/2] gstreamer: allocator: gst_libcamera_allocator_new():\n\tFix memory leak","Message-ID":"<20250106100613.493108-2-pobrn@protonmail.com>","In-Reply-To":"<20250106100613.493108-1-pobrn@protonmail.com>","References":"<20250106100613.493108-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"7d7333e8ad624e713c54700ce8286e98fa2fd68c","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"},"content":"If `FrameBufferAllocator::allocate()` causes the construction to be\naborted, the allocated `GstLibcameraAllocator` will not be\ndeallocated properly. Use `g_autoptr()` to address this.\n\n`g_steal_pointer()` could only be used in glib 2.68 or later because\nearlier it evaluates to a pointer-to-void in C++, which would necessitate\na `static_cast`.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nChanges in v3:\n  - fix #include order\n\nChanges in v2:\n  - add `#include <utility>`\n---\n src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\n--\n2.47.1","diff":"diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\nindex b0c84893a..d4492d994 100644\n--- a/src/gstreamer/gstlibcameraallocator.cpp\n+++ b/src/gstreamer/gstlibcameraallocator.cpp\n@@ -8,6 +8,8 @@\n\n #include \"gstlibcameraallocator.h\"\n\n+#include <utility>\n+\n #include <libcamera/camera.h>\n #include <libcamera/framebuffer_allocator.h>\n #include <libcamera/stream.h>\n@@ -199,15 +201,13 @@ GstLibcameraAllocator *\n gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n \t\t\t    CameraConfiguration *config_)\n {\n-\tauto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n-\t\t\t\t\t\t\t  nullptr));\n+\tg_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n+\t\t\t\t\t\t\t\t\t\t     nullptr));\n \tgint ret;\n\n \tself->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));\n-\tif (ret) {\n-\t\tg_object_unref(self);\n+\tif (ret)\n \t\treturn nullptr;\n-\t}\n\n \tself->fb_allocator = new FrameBufferAllocator(camera);\n \tfor (StreamConfiguration &streamCfg : *config_) {\n@@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n \t\tg_hash_table_insert(self->pools, stream, pool);\n \t}\n\n-\treturn self;\n+\treturn std::exchange(self, nullptr);\n }\n\n bool\n","prefixes":["v3","2/2"]}