Message ID | 20240803211007.18330-1-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
2024. augusztus 3., szombat 23:10 keltezéssel, Laurent Pinchart <laurent.pinchart@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@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. Also, why not use `std::unique_ptr<uint8_t[]> lineBuffers_[kMaxLineBuffers];` instead? Regards, Barnabás Pőcze > return -ENOMEM; > } > > base-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5 > -- > Regards, > > Laurent Pinchart > >
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@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@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
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]) return -ENOMEM; }
libcamera is implemented in C++, use new[]() instead of malloc() (and delete[]() instead of free()). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- src/libcamera/software_isp/debayer_cpu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) base-commit: 19bbca3c0b376ba0183f5db53472c8c46cd402b5