From ff2ee0174ca62ab4460adfe20049ed05f52615c5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 8 Dec 2020 03:40:25 +0200 Subject: 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 Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- include/libcamera/internal/v4l2_subdevice.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/libcamera') diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 02ee3e91..eb25fa2f 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__ #define __LIBCAMERA_INTERNAL_V4L2_SUBDEVICE_H__ +#include #include #include @@ -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 + fromEntityName(const MediaDevice *media, const std::string &entity); protected: std::string logPrefix() const override; -- cgit v1.2.1