[{"id":32742,"web_url":"https://patchwork.libcamera.org/comment/32742/","msgid":"<20241215214535.GT9975@pendragon.ideasonboard.com>","date":"2024-12-15T21:45:35","subject":"Re: [PATCH v1 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Sun, Dec 15, 2024 at 06:18:44PM +0000, Barnabás Pőcze wrote:\n> If `FrameBufferAllocator::allocate()` causes the construction to be\n> aborted, the allocated `GstLibcameraAllocator` will not be\n> deallocated properly. Use `g_autoptr()` to address this.\n> \n> `g_steal_pointer()` cannot be used because that evaluates to\n> an expression of type `void *`, so one would need an extra static_cast.\n> Instead, use `std::exchange()`.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/gstreamer/gstlibcameraallocator.cpp | 10 ++++------\n>  1 file changed, 4 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index b0c84893a..341bd31b3 100644\n> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> @@ -199,15 +199,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 +226,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#include <utility>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  }\n>  \n>  bool","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 70207C32F5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 15 Dec 2024 21:45:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8117D67F29;\n\tSun, 15 Dec 2024 22:45:53 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B3D7C67F1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Dec 2024 22:45:52 +0100 (CET)","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 7718499F;\n\tSun, 15 Dec 2024 22:45:16 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ssKtNijl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734299116;\n\tbh=reV0JhOVYh12bylg323zQuw9/kF1exiHMKBH0G6noSg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ssKtNijlw6u978ZHLTglBWzF4EGWvEVz5/ee5QHavhqpH5ASsXg/HyBeB/4ElDBVf\n\tSWrYf4XSRvOBhqqJyby5jFFiUFyFxTeMNDd1UEdPorvamUETe7w1kS6GyAqTdsZXMp\n\tQ4s0ej5Nk6b1r3aweYJdWngRaDv69ybODyhvudZQ=","Date":"Sun, 15 Dec 2024 23:45:35 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","Message-ID":"<20241215214535.GT9975@pendragon.ideasonboard.com>","References":"<20241215181835.802589-1-pobrn@protonmail.com>\n\t<20241215181835.802589-2-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20241215181835.802589-2-pobrn@protonmail.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>"}}]