libcamera: pipeline_handler: Return unique_ptr from generateConfiguration()
The PipelineHandler::generateConfiguration() function allocates a CameraConfiguration instance and returns it. The ownership of the instance is transferred to the caller. This is a perfect match for a std::unique_ptr<>, which the Camera::generateConfiguration() function already returns. Update PipelineHandler::generateConfiguration() to match it. This fixes a memory leak in one of the error return paths in the IPU3 pipeline handler. While at it, update the Camera::generateConfiguration() function documentation to drop the sentence that describes the ownership transfer, as that is implied by usage of std::unique_ptr<>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
@@ -323,7 +323,8 @@ class PipelineHandlerRPi : public PipelineHandler
|
||||
public:
|
||||
PipelineHandlerRPi(CameraManager *manager);
|
||||
|
||||
CameraConfiguration *generateConfiguration(Camera *camera, const StreamRoles &roles) override;
|
||||
std::unique_ptr<CameraConfiguration> generateConfiguration(Camera *camera,
|
||||
const StreamRoles &roles) override;
|
||||
int configure(Camera *camera, CameraConfiguration *config) override;
|
||||
|
||||
int exportFrameBuffers(Camera *camera, Stream *stream,
|
||||
@@ -561,11 +562,12 @@ PipelineHandlerRPi::PipelineHandlerRPi(CameraManager *manager)
|
||||
{
|
||||
}
|
||||
|
||||
CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
|
||||
const StreamRoles &roles)
|
||||
std::unique_ptr<CameraConfiguration>
|
||||
PipelineHandlerRPi::generateConfiguration(Camera *camera, const StreamRoles &roles)
|
||||
{
|
||||
RPiCameraData *data = cameraData(camera);
|
||||
CameraConfiguration *config = new RPiCameraConfiguration(data);
|
||||
std::unique_ptr<CameraConfiguration> config =
|
||||
std::make_unique<RPiCameraConfiguration>(data);
|
||||
V4L2SubdeviceFormat sensorFormat;
|
||||
unsigned int bufferCount;
|
||||
PixelFormat pixelFormat;
|
||||
@@ -640,13 +642,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
|
||||
default:
|
||||
LOG(RPI, Error) << "Requested stream role not supported: "
|
||||
<< role;
|
||||
delete config;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (rawCount > 1 || outCount > 2) {
|
||||
LOG(RPI, Error) << "Invalid stream roles requested";
|
||||
delete config;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user