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:
Laurent Pinchart 2022-10-03 22:55:11 +03:00
parent 5a867f312c
commit ba3a1adc13
4 changed files with 13 additions and 11 deletions

View file

@ -142,10 +142,10 @@ void CameraManager::Private::createPipelineHandlers()
* file and only fallback on all handlers if there is no
* configuration file.
*/
std::vector<PipelineHandlerFactory *> &factories =
const std::vector<PipelineHandlerFactory *> &factories =
PipelineHandlerFactory::factories();
for (PipelineHandlerFactory *factory : factories) {
for (const PipelineHandlerFactory *factory : factories) {
LOG(Camera, Debug)
<< "Found registered pipeline handler '"
<< factory->name() << "'";

View file

@ -678,9 +678,9 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name)
*/
std::shared_ptr<PipelineHandler> PipelineHandlerFactory::create(CameraManager *manager) const
{
PipelineHandler *handler = createInstance(manager);
std::unique_ptr<PipelineHandler> handler = createInstance(manager);
handler->name_ = name_.c_str();
return std::shared_ptr<PipelineHandler>(handler);
return std::shared_ptr<PipelineHandler>(std::move(handler));
}
/**
@ -727,8 +727,8 @@ std::vector<PipelineHandlerFactory *> &PipelineHandlerFactory::factories()
* macro. It creates a pipeline handler instance associated with the camera
* \a manager.
*
* \return a pointer to a newly constructed instance of the PipelineHandler
* subclass corresponding to the factory
* \return A unique pointer to a newly constructed instance of the
* PipelineHandler subclass corresponding to the factory
*/
/**