{"id":22344,"url":"https://patchwork.libcamera.org/api/1.1/patches/22344/?format=json","web_url":"https://patchwork.libcamera.org/patch/22344/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20241216104704.957343-2-pobrn@protonmail.com>","date":"2024-12-16T10:47:12","name":"[v2,2/2] gstreamer: allocator: gst_libcamera_allocator_new(): Fix memory leak","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ef0db0bde02ada0d4edc56c7b1e81c90c9edf3e6","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/1.1/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22344/mbox/","series":[{"id":4894,"url":"https://patchwork.libcamera.org/api/1.1/series/4894/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4894","date":"2024-12-16T10:47:07","name":"[v2,1/2] gstreamer: allocator: gst_libcamera_allocator_new(): Recognize errors","version":2,"mbox":"https://patchwork.libcamera.org/series/4894/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22344/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22344/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 40A44C32F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 10:47:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F20F767F50;\n\tMon, 16 Dec 2024 11:47:19 +0100 (CET)","from mail-4322.protonmail.ch (mail-4322.protonmail.ch\n\t[185.70.43.22])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C0A1767F37\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 11:47:17 +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=\"P3lgaEey\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1734346037; x=1734605237;\n\tbh=elhpjPOB0d6LOdy8kpfwqZP+cJCvs+YA9E6zixlUGs8=;\n\th=Date:To:From: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=P3lgaEey11U5znXHndbDA12/3zrEtxwvP5dQhLp9c5oB8v6qmD8uu5Ju520nsuIpF\n\t0o+AVkLQ8L1PNkNlQHKkKJ+OsxN+ZNZPuy9rmxkxxrSRDRt21DKFBSfK/4izykB2zU\n\tHXFjqEUYL2vCTgDBmVeC6N9ArIBciSR2S64xmRvFFnt+pNTDEdsCsk5OKLkqvI7qe6\n\te8EGMcnTvdI0yAK39U+wUfp72WR5+BNo7pt+JCnL6RBkNCzPjlhie2c4UVUCxxATPv\n\taoKZWTIFNmG/k7zpHo8WEg3xWvK2HFVYid8lunGartigS19bsbA2c1755j9TXX5DGz\n\tJ2Z0c6Frco+dg==","Date":"Mon, 16 Dec 2024 10:47:12 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Subject":"[PATCH v2 2/2] gstreamer: allocator: gst_libcamera_allocator_new():\n\tFix memory leak","Message-ID":"<20241216104704.957343-2-pobrn@protonmail.com>","In-Reply-To":"<20241216104704.957343-1-pobrn@protonmail.com>","References":"<20241216104704.957343-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"35cce4d229c508f6d3f3ae4243b98957732be0cb","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>\n---\n src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)","diff":"diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\nindex b0c84893a..57405e083 100644\n--- a/src/gstreamer/gstlibcameraallocator.cpp\n+++ b/src/gstreamer/gstlibcameraallocator.cpp\n@@ -6,6 +6,8 @@\n  * GStreamer Custom Allocator\n  */\n \n+#include <utility>\n+\n #include \"gstlibcameraallocator.h\"\n \n #include <libcamera/camera.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":["v2","2/2"]}