From patchwork Mon Oct 3 21:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17513 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 01575BD16B for ; Mon, 3 Oct 2022 21:21:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9260601C7; Mon, 3 Oct 2022 23:21:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664832098; bh=8NocbKuZ5437S7CzPy5r1JD5H2NzdLJnsKimXgve9OQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zk210YQFYHpS4PhfbO4b7Zd0qfqgsBp0TnXpODIu7vhUYcXL/+ZlyzRpn9vgMZTEV 9fpbGuY5NiB1VLJ13efw3Ijv5siWrgTlNOZxVdBmE4u0bc8EXYTDCQ181i3Fjg/7MR SpYpk+hN1kLBJ5vBLu8TvZWdvb0YGtGRE8XpWJHJo2OmKHtGyZTHQkDW+i3c4VgxC8 0Jxww26QyxRJYdeT/lNP1W39Ri38v1Njm3elCsKzkxhXH8C+A1ZghWijgYAFlYGtab icE0/JnHJzBBlhIyAZi6cbDpX/I1BAa4yk/QEm4w3pTO4q0UIF3HEC35NBPe1Sby9A UGLUt8vII2Kdg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EE6B60A70 for ; Mon, 3 Oct 2022 23:21:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eu4M2CwL"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBDF8440 for ; Mon, 3 Oct 2022 23:21:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664832096; bh=8NocbKuZ5437S7CzPy5r1JD5H2NzdLJnsKimXgve9OQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eu4M2CwL3yhFbydgaLj8BIdAVIOUNT7qkDtcUIGX6VUm3q1PDs8uLrp/2D7kxTiUo CtTz7O135/y3x74TXNfylIp1VBjzQBhOraYsf8Jrfbz3wN3bKllINPgtTcM7nuwpHe iDFKH0SV3zFdH6l1zap3Jah3Wq70FWD4DCD6Rc7Q= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Oct 2022 00:21:23 +0300 Message-Id: <20221003212128.32429-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> References: <20221003212128.32429-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/8] ipa: camera_sensor_helper: Return unique_ptr from createInstance 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Avoid naked pointer with memory allocation by returning a unique_ptr from CameraSensorHelperFactory::createInstance(), in order to increase memory allocation safety. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 7 +++---- src/ipa/libipa/camera_sensor_helper.h | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index fde9bf5b8892..3a7d701d8616 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -261,8 +261,7 @@ std::unique_ptr CameraSensorHelperFactory::create(const std: if (name != factory->name_) continue; - CameraSensorHelper *helper = factory->createInstance(); - return std::unique_ptr(helper); + return factory->createInstance(); } return nullptr; @@ -307,8 +306,8 @@ std::vector &CameraSensorHelperFactory::factories() * macro. It creates a camera sensor helper instance associated with the camera * sensor model. * - * \return A pointer to a newly constructed instance of the CameraSensorHelper - * subclass corresponding to the factory + * \return A unique pointer to a newly constructed instance of the + * CameraSensorHelper subclass corresponding to the factory */ /** diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 410156efb2ea..21ee43cc9f9f 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -73,7 +73,7 @@ private: static void registerType(CameraSensorHelperFactory *factory); - virtual CameraSensorHelper *createInstance() const = 0; + virtual std::unique_ptr createInstance() const = 0; std::string name_; }; @@ -85,9 +85,9 @@ public: \ helper##Factory() : CameraSensorHelperFactory(name) {} \ \ private: \ - CameraSensorHelper *createInstance() const \ + std::unique_ptr createInstance() const \ { \ - return new helper(); \ + return std::make_unique(); \ } \ }; \ static helper##Factory global_##helper##Factory;