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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
@@ -113,7 +113,8 @@ public:
|
||||
private:
|
||||
static void registerType(PipelineHandlerFactory *factory);
|
||||
|
||||
virtual PipelineHandler *createInstance(CameraManager *manager) const = 0;
|
||||
virtual std::unique_ptr<PipelineHandler>
|
||||
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<PipelineHandler> \
|
||||
createInstance(CameraManager *manager) const \
|
||||
{ \
|
||||
return new handler(manager); \
|
||||
return std::make_unique<handler>(manager); \
|
||||
} \
|
||||
}; \
|
||||
static handler##Factory global_##handler##Factory;
|
||||
|
||||
Reference in New Issue
Block a user