From 9d9481188fc3a4291b33a2d53e9e331cc2d7a023 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 3 Oct 2022 22:55:11 +0300 Subject: ipa: camera_sensor_helper: Return unique_ptr from createInstance Avoid naked pointer with memory allocation by returning a unique_ptr from CameraSensorHelperFactory::createInstance(), in order to increase memory allocation safety. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 7 +++---- src/ipa/libipa/camera_sensor_helper.h | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/ipa') diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index fde9bf5b..3a7d701d 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -261,8 +261,7 @@ std::unique_ptr CameraSensorHelperFactory::create(const std: if (name != factory->name_) continue; - CameraSensorHelper *helper = factory->createInstance(); - return std::unique_ptr(helper); + return factory->createInstance(); } return nullptr; @@ -307,8 +306,8 @@ std::vector &CameraSensorHelperFactory::factories() * macro. It creates a camera sensor helper instance associated with the camera * sensor model. * - * \return A pointer to a newly constructed instance of the CameraSensorHelper - * subclass corresponding to the factory + * \return A unique pointer to a newly constructed instance of the + * CameraSensorHelper subclass corresponding to the factory */ /** diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h index 410156ef..21ee43cc 100644 --- a/src/ipa/libipa/camera_sensor_helper.h +++ b/src/ipa/libipa/camera_sensor_helper.h @@ -73,7 +73,7 @@ private: static void registerType(CameraSensorHelperFactory *factory); - virtual CameraSensorHelper *createInstance() const = 0; + virtual std::unique_ptr createInstance() const = 0; std::string name_; }; @@ -85,9 +85,9 @@ public: \ helper##Factory() : CameraSensorHelperFactory(name) {} \ \ private: \ - CameraSensorHelper *createInstance() const \ + std::unique_ptr createInstance() const \ { \ - return new helper(); \ + return std::make_unique(); \ } \ }; \ static helper##Factory global_##helper##Factory; -- cgit v1.2.1