[PATCH] libcamera: software_isp: Replace malloc() with new[]()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Aug 4 13:44:53 CEST 2024


Hi Barnabás,

On Sat, Aug 03, 2024 at 10:59:22PM +0000, Barnabás Pőcze wrote:
> 2024. augusztus 3., szombat 23:10 keltezéssel, Laurent Pinchart <laurent.pinchart at ideasonboard.com> írta:
> 
> > libcamera is implemented in C++, use new[]() instead of malloc() (and
> > delete[]() instead of free()).
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > ---
> >  src/libcamera/software_isp/debayer_cpu.cpp | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
> > index f8d2677d657a..249294efca01 100644
> > --- a/src/libcamera/software_isp/debayer_cpu.cpp
> > +++ b/src/libcamera/software_isp/debayer_cpu.cpp
> > @@ -57,7 +57,7 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats)
> >  DebayerCpu::~DebayerCpu()
> >  {
> >  	for (unsigned int i = 0; i < kMaxLineBuffers; i++)
> > -		free(lineBuffers_[i]);
> > +		delete[] lineBuffers_[i];
> >  }
> > 
> >  #define DECLARE_SRC_POINTERS(pixel_t)                            \
> > @@ -529,8 +529,8 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,
> >  	for (unsigned int i = 0;
> >  	     i < (inputConfig_.patternSize.height + 1) && enableInputMemcpy_;
> >  	     i++) {
> > -		free(lineBuffers_[i]);
> > -		lineBuffers_[i] = (uint8_t *)malloc(lineBufferLength_);
> > +		delete[] lineBuffers_[i];
> > +		lineBuffers_[i] = new uint8_t[lineBufferLength_];
> >  		if (!lineBuffers_[i])
> 
> The condition can now never be true.

Oops indeed. I'll fix that in v2.

> Also, why not use `std::unique_ptr<uint8_t[]> lineBuffers_[kMaxLineBuffers];` instead?

That, or `std::vector<uint8_t> lineBuffers_[kMaxLineBuffers]`. I'll do
that in v2.

> >  			return -ENOMEM;
> >  	}
> > 
> > base-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list