[libcamera-devel,v2,09/13] libcamera: v4l2_subdevice: Close subdevice when destroyed

Message ID 20190416220839.1577-10-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • Rockchip ISP pipeline handler
Related show

Commit Message

Laurent Pinchart April 16, 2019, 10:08 p.m. UTC
Make sure the subdevice file descriptor isn't leaked by closing it when
the V4L2Subdevice instance is destroyed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/include/v4l2_subdevice.h | 1 +
 src/libcamera/v4l2_subdevice.cpp       | 5 +++++
 2 files changed, 6 insertions(+)

Comments

Niklas Söderlund April 16, 2019, 10:59 p.m. UTC | #1
Hi Laurent,

Thanks for your patch.

On 2019-04-17 01:08:35 +0300, Laurent Pinchart wrote:
> Make sure the subdevice file descriptor isn't leaked by closing it when
> the V4L2Subdevice instance is destroyed.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/libcamera/include/v4l2_subdevice.h | 1 +
>  src/libcamera/v4l2_subdevice.cpp       | 5 +++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index c71dce7d8644..e592d67dd043 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -35,6 +35,7 @@ public:
>  	explicit V4L2Subdevice(const MediaEntity *entity);
>  	V4L2Subdevice(const V4L2Subdevice &) = delete;
>  	V4L2Subdevice &operator=(const V4L2Subdevice &) = delete;
> +	~V4L2Subdevice();
>  
>  	int open();
>  	bool isOpen() const;
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index e34cc1693b46..a03fadfd579e 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -112,6 +112,11 @@ V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)
>  {
>  }
>  
> +V4L2Subdevice::~V4L2Subdevice()
> +{
> +	close();
> +}
> +
>  /**
>   * \brief Open a V4L2 subdevice
>   *
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi April 17, 2019, 8:03 a.m. UTC | #2
Hi Laurent,
   I was surprised as well we didn't have this!

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

On Wed, Apr 17, 2019 at 01:08:35AM +0300, Laurent Pinchart wrote:
> Make sure the subdevice file descriptor isn't leaked by closing it when
> the V4L2Subdevice instance is destroyed.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/libcamera/include/v4l2_subdevice.h | 1 +
>  src/libcamera/v4l2_subdevice.cpp       | 5 +++++
>  2 files changed, 6 insertions(+)
>
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index c71dce7d8644..e592d67dd043 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -35,6 +35,7 @@ public:
>  	explicit V4L2Subdevice(const MediaEntity *entity);
>  	V4L2Subdevice(const V4L2Subdevice &) = delete;
>  	V4L2Subdevice &operator=(const V4L2Subdevice &) = delete;
> +	~V4L2Subdevice();
>
>  	int open();
>  	bool isOpen() const;
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index e34cc1693b46..a03fadfd579e 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -112,6 +112,11 @@ V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)
>  {
>  }
>
> +V4L2Subdevice::~V4L2Subdevice()
> +{
> +	close();
> +}
> +
>  /**
>   * \brief Open a V4L2 subdevice
>   *
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
index c71dce7d8644..e592d67dd043 100644
--- a/src/libcamera/include/v4l2_subdevice.h
+++ b/src/libcamera/include/v4l2_subdevice.h
@@ -35,6 +35,7 @@  public:
 	explicit V4L2Subdevice(const MediaEntity *entity);
 	V4L2Subdevice(const V4L2Subdevice &) = delete;
 	V4L2Subdevice &operator=(const V4L2Subdevice &) = delete;
+	~V4L2Subdevice();
 
 	int open();
 	bool isOpen() const;
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index e34cc1693b46..a03fadfd579e 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -112,6 +112,11 @@  V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity)
 {
 }
 
+V4L2Subdevice::~V4L2Subdevice()
+{
+	close();
+}
+
 /**
  * \brief Open a V4L2 subdevice
  *