[libcamera-devel,v2,3/4] test: log: log_api: Close open fds on error paths

Message ID 20200515124245.18040-4-email@uajain.com
State Accepted
Headers show
Series
  • Coverity scan fixes
Related show

Commit Message

Umang Jain May 15, 2020, 12:42 p.m. UTC
Pointed out by Coverity DefectId=279091

Signed-off-by: Umang Jain <email@uajain.com>
---
 test/log/log_api.cpp | 2 ++
 1 file changed, 2 insertions(+)

Comments

Kieran Bingham June 2, 2020, 9:39 a.m. UTC | #1
Hi Umang,

On 15/05/2020 13:42, Umang Jain wrote:
> Pointed out by Coverity DefectId=279091

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

> Signed-off-by: Umang Jain <email@uajain.com>
> ---
>  test/log/log_api.cpp | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp
> index 33622f8..4d2c8db 100644
> --- a/test/log/log_api.cpp
> +++ b/test/log/log_api.cpp
> @@ -86,6 +86,7 @@ protected:
>  
>  		if (logSetFile(path) < 0) {
>  			cerr << "Failed to set log file" << endl;
> +			close(fd);
>  			return TestFail;
>  		}
>  
> @@ -96,6 +97,7 @@ protected:
>  		lseek(fd, 0, SEEK_SET);
>  		if (read(fd, buf, sizeof(buf)) < 0) {
>  			cerr << "Failed to read tmp log file" << endl;
> +			close(fd);
>  			return TestFail;
>  		}
>  		close(fd);
>

Patch

diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp
index 33622f8..4d2c8db 100644
--- a/test/log/log_api.cpp
+++ b/test/log/log_api.cpp
@@ -86,6 +86,7 @@  protected:
 
 		if (logSetFile(path) < 0) {
 			cerr << "Failed to set log file" << endl;
+			close(fd);
 			return TestFail;
 		}
 
@@ -96,6 +97,7 @@  protected:
 		lseek(fd, 0, SEEK_SET);
 		if (read(fd, buf, sizeof(buf)) < 0) {
 			cerr << "Failed to read tmp log file" << endl;
+			close(fd);
 			return TestFail;
 		}
 		close(fd);