From patchwork Mon Jan 6 10:06:16 2025 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: 22454 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 0CC5AC3257 for ; Mon, 6 Jan 2025 10:06:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E500D684E2; Mon, 6 Jan 2025 11:06:22 +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="dPujPZWa"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DCDC608AB for ; Mon, 6 Jan 2025 11:06:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1736157981; x=1736417181; bh=ePjn5HvU0udlq8bTo7GChoHPsN/azCpmTcbyqXuWdao=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=dPujPZWa++JlH84GQUZpmAul3CL5PoZuSFfRE/CaeZqBHrXWsaNXwle9hn7aMsFSW ehM/xsQNN2C3jGOy4WYWEDcZu2FX0jac+fEz83vHxg0QdagIW+Gzbh7kX/YIli1r7r H/4+eQz+fyv+6UPbpi7MxLXb+61uYbYv3tP4zmhV9z7NArKcp3ALbIVEwDmBQt6/QL ZllVhUXK52ZSbMEq2AUr1p7sqEdGINUo9JBPZsVbEIO6Pv4dDLBem+hxN/SveRZe40 Q6nrFe0zSYNB8fl8cZ+jzV1hIZ44PxIdDB+7mdp5p8GtK4EaJVGUiPE3wrjmWFpMLD b5EOoIDkjfeRQ== Date: Mon, 06 Jan 2025 10:06:16 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Cc: Laurent Pinchart , Nicolas Dufresne Subject: [PATCH v3 1/2] gstreamer: allocator: gst_libcamera_allocator_new(): Recognize errors Message-ID: <20250106100613.493108-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: ad987dd89b5e3c22bae226b0d158640cac6a57c6 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" `FrameBufferAllocator::allocate()` might return a negative error code, but currently this is handled the same way as success. So instead of continuing, abort the construction of the allocator object. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- Changes in v3: none Changes in v2: none --- src/gstreamer/gstlibcameraallocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.47.1 diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp index 7e4c904da..b0c84893a 100644 --- a/src/gstreamer/gstlibcameraallocator.cpp +++ b/src/gstreamer/gstlibcameraallocator.cpp @@ -214,7 +214,7 @@ gst_libcamera_allocator_new(std::shared_ptr camera, Stream *stream = streamCfg.stream(); ret = self->fb_allocator->allocate(stream); - if (ret == 0) + if (ret <= 0) return nullptr; GQueue *pool = g_queue_new(); From patchwork Mon Jan 6 10:06:22 2025 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: 22455 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 9254AC32D4 for ; Mon, 6 Jan 2025 10:06:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 06506684EA; Mon, 6 Jan 2025 11:06:30 +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="KhuGRfEI"; dkim-atps=neutral Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50543684E1 for ; Mon, 6 Jan 2025 11:06:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1736157987; x=1736417187; bh=RUYbbDRZpY+InpodoobX2qRjgDsVnbWFkNnwOoqzK9I=; h=Date:To:From:Cc: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=KhuGRfEI1dK6gcb6SmnodryzFBXnnvKvqBOosXCBUPPBGHcjoK+CT7Nz35rBRYXEL lJ55ZqJ9UjuLb8u5WraSRy5loqXBKT8tl5tmUbiCFRp9l3fw7+w5DR5r/ZBXgKQ4hK vrlg40HweWPnFR3UhhJ+Jyurs4Xov1Btv4mNi6HEkM9V4etzXAlixCmI+iQjR8FJ6H aWJFJ074CMAlGaR+AyHcpK+jz6SdQjiPeBPPs89QLg2So4PwNBG+9cq8GjCYU7dUq3 3B24/jDq38ALVvOJt2hnE8YJA8cZcI5afiDEa9G1YWnD1xJC3ien4NIdd31sHq/PxS vzKq2J9fPkn0w== 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?= Cc: Laurent Pinchart Subject: [PATCH v3 2/2] gstreamer: allocator: gst_libcamera_allocator_new(): Fix 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 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 Reviewed-by: Kieran Bingham Reviewed-by: Nicolas Dufresne --- Changes in v3: - fix #include order Changes in v2: - add `#include ` --- src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.47.1 diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp index b0c84893a..d4492d994 100644 --- a/src/gstreamer/gstlibcameraallocator.cpp +++ b/src/gstreamer/gstlibcameraallocator.cpp @@ -8,6 +8,8 @@ #include "gstlibcameraallocator.h" +#include + #include #include #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