[{"id":30562,"web_url":"https://patchwork.libcamera.org/comment/30562/","msgid":"<csqgDli2heZ7gQVvUSLYpsg7aYviP0eNqnTf7gYR37y1qnBWPy6jV6SSuLZulb_IufjEBfBGU2ScVCugyz9rFMmwuXkRHARd7Yghfcw_NXM=@protonmail.com>","date":"2024-08-03T22:59:22","subject":"Re: [PATCH] libcamera: software_isp: Replace malloc() with new[]()","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"2024. augusztus 3., szombat 23:10 keltezéssel, Laurent Pinchart <laurent.pinchart@ideasonboard.com> írta:\n\n> libcamera is implemented in C++, use new[]() instead of malloc() (and\n> delete[]() instead of free()).\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/software_isp/debayer_cpu.cpp | 6 +++---\n>  1 file changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> index f8d2677d657a..249294efca01 100644\n> --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> @@ -57,7 +57,7 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n>  DebayerCpu::~DebayerCpu()\n>  {\n>  \tfor (unsigned int i = 0; i < kMaxLineBuffers; i++)\n> -\t\tfree(lineBuffers_[i]);\n> +\t\tdelete[] lineBuffers_[i];\n>  }\n> \n>  #define DECLARE_SRC_POINTERS(pixel_t)                            \\\n> @@ -529,8 +529,8 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n>  \tfor (unsigned int i = 0;\n>  \t     i < (inputConfig_.patternSize.height + 1) && enableInputMemcpy_;\n>  \t     i++) {\n> -\t\tfree(lineBuffers_[i]);\n> -\t\tlineBuffers_[i] = (uint8_t *)malloc(lineBufferLength_);\n> +\t\tdelete[] lineBuffers_[i];\n> +\t\tlineBuffers_[i] = new uint8_t[lineBufferLength_];\n>  \t\tif (!lineBuffers_[i])\n\nThe condition can now never be true.\n\nAlso, why not use `std::unique_ptr<uint8_t[]> lineBuffers_[kMaxLineBuffers];` instead?\n\n\nRegards,\nBarnabás Pőcze\n\n\n>  \t\t\treturn -ENOMEM;\n>  \t}\n> \n> base-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5\n> --\n> Regards,\n> \n> Laurent Pinchart\n> \n>","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 41450BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 Aug 2024 22:59:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6EB446337D;\n\tSun,  4 Aug 2024 00:59:30 +0200 (CEST)","from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B85063370\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 00:59:28 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"UqiKlZ/5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1722725967; x=1722985167;\n\tbh=mb8xzCJrNvSp7ckl16Hp3FokAhfgMOTYi+3QtwwsJBw=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector;\n\tb=UqiKlZ/5k0FIZGj276PDkLqEb0pHP5dpeXMfhn01XKpm52mcHgiG3/CC9WPaTNnok\n\ttzCj6XXHfcmusojogFaF3V+ju7hkk1JfvNV2kRetiyuYoeVOkiRlFyTz1LDU3g+MIo\n\tJnuyv/tQmitb2RDZnyWqVBGo1VveI8jx9q4DINoGiK3wJ++S5nRjD6/WYfIG33MuzE\n\tVaJDX2CPSx/NVNyvvHU926sCl94JrAdHAsUji4Pn8peScLIRs/ZhpKV1XtoGmiK16u\n\tPePYhvyeqaIi1XoW4IsAz286KMC0Ae9apLnmiLTyVegQn+8bkWID7zByO9RQwitNI6\n\t5g606PJAXK9Aw==","Date":"Sat, 03 Aug 2024 22:59:22 +0000","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: software_isp: Replace malloc() with new[]()","Message-ID":"<csqgDli2heZ7gQVvUSLYpsg7aYviP0eNqnTf7gYR37y1qnBWPy6jV6SSuLZulb_IufjEBfBGU2ScVCugyz9rFMmwuXkRHARd7Yghfcw_NXM=@protonmail.com>","In-Reply-To":"<20240803211007.18330-1-laurent.pinchart@ideasonboard.com>","References":"<20240803211007.18330-1-laurent.pinchart@ideasonboard.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"0adf2a7d1dff7fbf2eb4ce67c135fc007fd921d9","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"}},{"id":30564,"web_url":"https://patchwork.libcamera.org/comment/30564/","msgid":"<20240804114453.GL3319@pendragon.ideasonboard.com>","date":"2024-08-04T11:44:53","subject":"Re: [PATCH] libcamera: software_isp: Replace malloc() with new[]()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nOn Sat, Aug 03, 2024 at 10:59:22PM +0000, Barnabás Pőcze wrote:\n> 2024. augusztus 3., szombat 23:10 keltezéssel, Laurent Pinchart <laurent.pinchart@ideasonboard.com> írta:\n> \n> > libcamera is implemented in C++, use new[]() instead of malloc() (and\n> > delete[]() instead of free()).\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/software_isp/debayer_cpu.cpp | 6 +++---\n> >  1 file changed, 3 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\n> > index f8d2677d657a..249294efca01 100644\n> > --- a/src/libcamera/software_isp/debayer_cpu.cpp\n> > +++ b/src/libcamera/software_isp/debayer_cpu.cpp\n> > @@ -57,7 +57,7 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)\n> >  DebayerCpu::~DebayerCpu()\n> >  {\n> >  \tfor (unsigned int i = 0; i < kMaxLineBuffers; i++)\n> > -\t\tfree(lineBuffers_[i]);\n> > +\t\tdelete[] lineBuffers_[i];\n> >  }\n> > \n> >  #define DECLARE_SRC_POINTERS(pixel_t)                            \\\n> > @@ -529,8 +529,8 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n> >  \tfor (unsigned int i = 0;\n> >  \t     i < (inputConfig_.patternSize.height + 1) && enableInputMemcpy_;\n> >  \t     i++) {\n> > -\t\tfree(lineBuffers_[i]);\n> > -\t\tlineBuffers_[i] = (uint8_t *)malloc(lineBufferLength_);\n> > +\t\tdelete[] lineBuffers_[i];\n> > +\t\tlineBuffers_[i] = new uint8_t[lineBufferLength_];\n> >  \t\tif (!lineBuffers_[i])\n> \n> The condition can now never be true.\n\nOops indeed. I'll fix that in v2.\n\n> Also, why not use `std::unique_ptr<uint8_t[]> lineBuffers_[kMaxLineBuffers];` instead?\n\nThat, or `std::vector<uint8_t> lineBuffers_[kMaxLineBuffers]`. I'll do\nthat in v2.\n\n> >  \t\t\treturn -ENOMEM;\n> >  \t}\n> > \n> > base-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5","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 BBDB4BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  4 Aug 2024 11:45:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7C80463381;\n\tSun,  4 Aug 2024 13:45:16 +0200 (CEST)","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 8B9576192D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  4 Aug 2024 13:45:15 +0200 (CEST)","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 CA279289;\n\tSun,  4 Aug 2024 13:44:24 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lNVFf6QO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722771865;\n\tbh=Y+dh3Z3e8j4QR10YNNhyNldqo61V0bOdL8CqN+jwlRA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lNVFf6QOw8Sny+MZ0tcxPdBdl5WOLf3OXt0iyF6eArqIu/bWkyGb0ZQflLu7L+K7Q\n\tZB+s8a3z82wtTf8PDAEAvc+9/jBLFdw+mzX+5s1iJGPs9otw4gHx6+faouKn9cJ1yz\n\tn9BjX1XHKmxiVgZX79eE/ws6KnW/8BFsX8WAI65U=","Date":"Sun, 4 Aug 2024 14:44:53 +0300","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] libcamera: software_isp: Replace malloc() with new[]()","Message-ID":"<20240804114453.GL3319@pendragon.ideasonboard.com>","References":"<20240803211007.18330-1-laurent.pinchart@ideasonboard.com>\n\t<csqgDli2heZ7gQVvUSLYpsg7aYviP0eNqnTf7gYR37y1qnBWPy6jV6SSuLZulb_IufjEBfBGU2ScVCugyz9rFMmwuXkRHARd7Yghfcw_NXM=@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<csqgDli2heZ7gQVvUSLYpsg7aYviP0eNqnTf7gYR37y1qnBWPy6jV6SSuLZulb_IufjEBfBGU2ScVCugyz9rFMmwuXkRHARd7Yghfcw_NXM=@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>"}}]