[libcamera-devel,2/2] libcamera: v4l2_videodevice: Clear cache_ in ~V4L2BufferCache()
diff mbox series

Message ID 20210709114736.875760-2-umang.jain@ideasonboard.com
State Rejected
Headers show
Series
  • [libcamera-devel,1/2] libcamera: v4l2_videodevice: Correctly populate V4L2BufferCache cache
Related show

Commit Message

Umang Jain July 9, 2021, 11:47 a.m. UTC
This shall help release any taken reference, just in case.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 2 ++
 1 file changed, 2 insertions(+)

Comments

Kieran Bingham July 9, 2021, 2:20 p.m. UTC | #1
Hi Umang,

On 09/07/2021 12:47, Umang Jain wrote:
> This shall help release any taken reference, just in case.
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  src/libcamera/v4l2_videodevice.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index da2af6a1..1e33571c 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -190,6 +190,8 @@ V4L2BufferCache::~V4L2BufferCache()
>  {
>  	if (missCounter_ > cache_.size())
>  		LOG(V4L2, Debug) << "Cache misses: " << missCounter_;
> +
> +	cache_.clear();

This isn't needed as far as I'm aware.

cache_ is a vector<Entry> so upon destructor, the destructors of all the
elements contained with in it are called, before the memory is freed:

  https://en.cppreference.com/w/cpp/container/vector/~vector

--
Kieran

>  }
>  
>  /**
>
Jacopo Mondi July 9, 2021, 4:04 p.m. UTC | #2
Hi Umang, Kieran,

On Fri, Jul 09, 2021 at 03:20:40PM +0100, Kieran Bingham wrote:
> Hi Umang,
>
> On 09/07/2021 12:47, Umang Jain wrote:
> > This shall help release any taken reference, just in case.
> >
> > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> > ---
> >  src/libcamera/v4l2_videodevice.cpp | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> > index da2af6a1..1e33571c 100644
> > --- a/src/libcamera/v4l2_videodevice.cpp
> > +++ b/src/libcamera/v4l2_videodevice.cpp
> > @@ -190,6 +190,8 @@ V4L2BufferCache::~V4L2BufferCache()
> >  {
> >  	if (missCounter_ > cache_.size())
> >  		LOG(V4L2, Debug) << "Cache misses: " << missCounter_;
> > +
> > +	cache_.clear();
>
> This isn't needed as far as I'm aware.
>
> cache_ is a vector<Entry> so upon destructor, the destructors of all the
> elements contained with in it are called, before the memory is freed:
>
>   https://en.cppreference.com/w/cpp/container/vector/~vector

That's my understanding as well!

Thanks
  j

>
> --
> Kieran
>
> >  }
> >
> >  /**
> >
Laurent Pinchart July 11, 2021, 8:24 p.m. UTC | #3
On Fri, Jul 09, 2021 at 06:04:10PM +0200, Jacopo Mondi wrote:
> Hi Umang, Kieran,
> 
> On Fri, Jul 09, 2021 at 03:20:40PM +0100, Kieran Bingham wrote:
> > Hi Umang,
> >
> > On 09/07/2021 12:47, Umang Jain wrote:
> > > This shall help release any taken reference, just in case.
> > >
> > > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> > > ---
> > >  src/libcamera/v4l2_videodevice.cpp | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> > > index da2af6a1..1e33571c 100644
> > > --- a/src/libcamera/v4l2_videodevice.cpp
> > > +++ b/src/libcamera/v4l2_videodevice.cpp
> > > @@ -190,6 +190,8 @@ V4L2BufferCache::~V4L2BufferCache()
> > >  {
> > >  	if (missCounter_ > cache_.size())
> > >  		LOG(V4L2, Debug) << "Cache misses: " << missCounter_;
> > > +
> > > +	cache_.clear();
> >
> > This isn't needed as far as I'm aware.
> >
> > cache_ is a vector<Entry> so upon destructor, the destructors of all the
> > elements contained with in it are called, before the memory is freed:
> >
> >   https://en.cppreference.com/w/cpp/container/vector/~vector
> 
> That's my understanding as well!

Ditto.

> > >  }
> > >
> > >  /**

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index da2af6a1..1e33571c 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -190,6 +190,8 @@  V4L2BufferCache::~V4L2BufferCache()
 {
 	if (missCounter_ > cache_.size())
 		LOG(V4L2, Debug) << "Cache misses: " << missCounter_;
+
+	cache_.clear();
 }
 
 /**