libcamera: v4l2_subdevice: Return a unique pointer from fromEntityName()

The fromEntityName() function returns a pointer to a newly allocated
V4L2Subdevice instance, which must be deleted by the caller. This opens
the door to memory leaks. Return a unique pointer instead, which conveys
the API semantics better than a sentence in the documentation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Laurent Pinchart 2020-12-08 03:40:25 +02:00
parent 2795f333fc
commit ff2ee0174c
6 changed files with 13 additions and 16 deletions

View file

@ -7,6 +7,7 @@
#ifndef __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
#define __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__
#include <memory>
#include <string>
#include <vector>
@ -60,8 +61,8 @@ public:
int setFormat(unsigned int pad, V4L2SubdeviceFormat *format,
Whence whence = ActiveFormat);
static V4L2Subdevice *fromEntityName(const MediaDevice *media,
const std::string &entity);
static std::unique_ptr<V4L2Subdevice>
fromEntityName(const MediaDevice *media, const std::string &entity);
protected:
std::string logPrefix() const override;