From ba3a1adc13b9a2c2e92f438bcf5320d77bd08bd9 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 3 Oct 2022 22:55:11 +0300 Subject: libcamera: pipeline_handler: Return unique_ptr from createInstance Avoid naked pointer with memory allocation by returning a unique_ptr from PipelineHandlerFactory::createInstance(), in order to increase memory allocation safety. This allows iterating over factories in the CameraManager and unit tests using const pointers. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index ebbdf2aa..ad74dc82 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -113,7 +113,8 @@ public: private: static void registerType(PipelineHandlerFactory *factory); - virtual PipelineHandler *createInstance(CameraManager *manager) const = 0; + virtual std::unique_ptr + createInstance(CameraManager *manager) const = 0; std::string name_; }; @@ -125,9 +126,10 @@ public: \ handler##Factory() : PipelineHandlerFactory(#handler) {} \ \ private: \ - PipelineHandler *createInstance(CameraManager *manager) const \ + std::unique_ptr \ + createInstance(CameraManager *manager) const \ { \ - return new handler(manager); \ + return std::make_unique(manager); \ } \ }; \ static handler##Factory global_##handler##Factory; -- cgit v1.2.1