[libcamera-devel,4/4] vimc: fix close(-1)

Message ID 20201007092239.41704-4-tomi.valkeinen@iki.fi
State Accepted
Headers show
Series
  • [libcamera-devel,1/4] cam: options: fix access to uninit variable
Related show

Commit Message

Tomi Valkeinen Oct. 7, 2020, 9:22 a.m. UTC
~IPAVimc() checks if fd != 0, but it should check if fd != -1.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
---
 src/ipa/vimc/vimc.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kieran Bingham Oct. 7, 2020, 9:34 a.m. UTC | #1
Hi Tomi,

On 07/10/2020 10:22, Tomi Valkeinen wrote:
> ~IPAVimc() checks if fd != 0, but it should check if fd != -1.
> 

Aha, - that explains a valgrind error I saw but hadn't yet investigated ;-)

Thanks

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
> ---
>  src/ipa/vimc/vimc.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp
> index ef25776..372a15f 100644
> --- a/src/ipa/vimc/vimc.cpp
> +++ b/src/ipa/vimc/vimc.cpp
> @@ -61,7 +61,7 @@ IPAVimc::IPAVimc()
>  
>  IPAVimc::~IPAVimc()
>  {
> -	if (fd_)
> +	if (fd_ != -1)
>  		::close(fd_);
>  }
>  
>
Laurent Pinchart Oct. 7, 2020, 1:31 p.m. UTC | #2
Hi Tomi,

Thank you for the patch.

On Wed, Oct 07, 2020 at 12:22:39PM +0300, Tomi Valkeinen wrote:
> ~IPAVimc() checks if fd != 0, but it should check if fd != -1.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>

We should use the FileDeescriptor class to handle file descriptors. But
this code will be reworked anyway, so for now,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/ipa/vimc/vimc.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp
> index ef25776..372a15f 100644
> --- a/src/ipa/vimc/vimc.cpp
> +++ b/src/ipa/vimc/vimc.cpp
> @@ -61,7 +61,7 @@ IPAVimc::IPAVimc()
>  
>  IPAVimc::~IPAVimc()
>  {
> -	if (fd_)
> +	if (fd_ != -1)
>  		::close(fd_);
>  }
>

Patch

diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp
index ef25776..372a15f 100644
--- a/src/ipa/vimc/vimc.cpp
+++ b/src/ipa/vimc/vimc.cpp
@@ -61,7 +61,7 @@  IPAVimc::IPAVimc()
 
 IPAVimc::~IPAVimc()
 {
-	if (fd_)
+	if (fd_ != -1)
 		::close(fd_);
 }