libcamera: Replace plain pointers with std::unique<>

libcamera uses std::unique_ptr<> to simplify life time management of
objects and avoid leaks. For historical reasons there are a fair number
of plain pointers with manual memory management. Replace them with
std::unique_ptr<> when the conversion is simple.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2026-04-24 01:17:37 +03:00
parent 0f9b73bae2
commit 1e4e158d98
16 changed files with 48 additions and 62 deletions
+2 -3
View File
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
sa.sa_handler = &signalHandler;
sigaction(SIGINT, &sa, nullptr);
CameraManager *cm = new libcamera::CameraManager();
std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>();
ret = cm->start();
if (ret) {
@@ -82,13 +82,12 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
MainWindow *mainWindow = new MainWindow(cm, options);
MainWindow *mainWindow = new MainWindow(cm.get(), options);
mainWindow->show();
ret = app.exec();
delete mainWindow;
cm->stop();
delete cm;
return ret;
}
+5 -6
View File
@@ -87,8 +87,8 @@ private:
};
MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
: saveRaw_(nullptr), options_(options), cm_(cm), allocator_(nullptr),
isCapturing_(false), captureRaw_(false)
: saveRaw_(nullptr), options_(options), cm_(cm), isCapturing_(false),
captureRaw_(false)
{
int ret;
@@ -450,7 +450,7 @@ int MainWindow::startCapture()
saveRaw_->setEnabled(config_->size() == 2);
/* Allocate and map buffers. */
allocator_ = new FrameBufferAllocator(camera_);
allocator_ = std::make_unique<FrameBufferAllocator>(camera_);
for (StreamConfiguration &config : *config_) {
Stream *stream = config.stream();
@@ -531,8 +531,7 @@ error:
freeBuffers_.clear();
delete allocator_;
allocator_ = nullptr;
allocator_.reset();
return ret;
}
@@ -564,7 +563,7 @@ void MainWindow::stopCapture()
requests_.clear();
freeQueue_.clear();
delete allocator_;
allocator_.reset();
isCapturing_ = false;
+1 -1
View File
@@ -109,7 +109,7 @@ private:
/* Camera manager, camera, configuration and buffers */
libcamera::CameraManager *cm_;
std::shared_ptr<libcamera::Camera> camera_;
libcamera::FrameBufferAllocator *allocator_;
std::unique_ptr<libcamera::FrameBufferAllocator> allocator_;
std::unique_ptr<libcamera::CameraConfiguration> config_;
std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>> mappedBuffers_;