[{"id":32764,"web_url":"https://patchwork.libcamera.org/comment/32764/","msgid":"<20241216112813.GN32204@pendragon.ideasonboard.com>","date":"2024-12-16T11:28:13","subject":"Re: [PATCH v2 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":"On Mon, Dec 16, 2024 at 10:47:12AM +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()` could only be used in glib 2.68 or later because\n> earlier it evaluates to a pointer-to-void in C++, which would necessitate\n> a `static_cast`.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n>  src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------\n>  1 file changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index 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\nThis should go after gstlibcameraallocator.h. Quoting codingstyle.rst,\n\nFor .cpp files, if the file implements an API declared in a header file,\nthat header file shall be included first in order to ensure it is\nself-contained.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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","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 026B4C32F9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 11:28:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8093267F5B;\n\tMon, 16 Dec 2024 12:28:31 +0100 (CET)","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 3AC2367EF1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 12:28:30 +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 8FAE213C;\n\tMon, 16 Dec 2024 12:27:53 +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=\"gtJQ7G0N\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734348473;\n\tbh=AtxVO5v/F0YPyHTEztGDKWwDwMsQTe9BFPXRnFyX75I=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gtJQ7G0NvqtAogHtUKkh0+5DxrPUw0fZoVx1uEepseBDwE4954OTFqmZULuW/Pp6+\n\twu4aGy5FHnSgqZsmUdRReuaGkX33aj6VMZ8x+jtuzg2BhJEKdt++qsWwdZhYK8gpGy\n\tcrKe4oAnubpFy6VmBXydRURTMBwrp+Fqwm8BQznI=","Date":"Mon, 16 Dec 2024 13:28:13 +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 v2 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","Message-ID":"<20241216112813.GN32204@pendragon.ideasonboard.com>","References":"<20241216104704.957343-1-pobrn@protonmail.com>\n\t<20241216104704.957343-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":"<20241216104704.957343-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>"}}]