From patchwork Mon Dec 16 10:47:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22344 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 40A44C32F6 for ; Mon, 16 Dec 2024 10:47:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F20F767F50; Mon, 16 Dec 2024 11:47:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="P3lgaEey"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0A1767F37 for ; Mon, 16 Dec 2024 11:47:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1734346037; x=1734605237; bh=elhpjPOB0d6LOdy8kpfwqZP+cJCvs+YA9E6zixlUGs8=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=P3lgaEey11U5znXHndbDA12/3zrEtxwvP5dQhLp9c5oB8v6qmD8uu5Ju520nsuIpF 0o+AVkLQ8L1PNkNlQHKkKJ+OsxN+ZNZPuy9rmxkxxrSRDRt21DKFBSfK/4izykB2zU HXFjqEUYL2vCTgDBmVeC6N9ArIBciSR2S64xmRvFFnt+pNTDEdsCsk5OKLkqvI7qe6 e8EGMcnTvdI0yAK39U+wUfp72WR5+BNo7pt+JCnL6RBkNCzPjlhie2c4UVUCxxATPv aoKZWTIFNmG/k7zpHo8WEg3xWvK2HFVYid8lunGartigS19bsbA2c1755j9TXX5DGz J2Z0c6Frco+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?= Subject: [PATCH v2 2/2] gstreamer: allocator: gst_libcamera_allocator_new(): Fix 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If `FrameBufferAllocator::allocate()` causes the construction to be aborted, the allocated `GstLibcameraAllocator` will not be deallocated properly. Use `g_autoptr()` to address this. `g_steal_pointer()` could only be used in glib 2.68 or later because earlier it evaluates to a pointer-to-void in C++, which would necessitate a `static_cast`. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp index b0c84893a..57405e083 100644 --- a/src/gstreamer/gstlibcameraallocator.cpp +++ b/src/gstreamer/gstlibcameraallocator.cpp @@ -6,6 +6,8 @@ * GStreamer Custom Allocator */ +#include + #include "gstlibcameraallocator.h" #include @@ -199,15 +201,13 @@ GstLibcameraAllocator * gst_libcamera_allocator_new(std::shared_ptr camera, CameraConfiguration *config_) { - auto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR, - nullptr)); + g_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR, + nullptr)); gint ret; self->cm_ptr = new std::shared_ptr(gst_libcamera_get_camera_manager(ret)); - if (ret) { - g_object_unref(self); + if (ret) return nullptr; - } self->fb_allocator = new FrameBufferAllocator(camera); for (StreamConfiguration &streamCfg : *config_) { @@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr camera, g_hash_table_insert(self->pools, stream, pool); } - return self; + return std::exchange(self, nullptr); } bool