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

Kieran Bingham kieran.bingham at ideasonboard.com
Tue Apr 14 13:29:45 CEST 2020


Hi Umang,

On 13/04/2020 11:46, Umang Jain wrote:
> Pointed out by Coverity DefectId=279091
> 

Looking at testFile(), doesn't the fd also leak after the call to
logSetFile(path) if that fails?

If there is the same issue in multiple places in a function I think it
should be handled by a single patch.


It would be nice of course if these releases could be handled
automatically - so perhaps converting things to use FileDescriptor
classes might help, though an initial glance looks like that will always
dup() the FD which might not be particularly desirable ...

I'll leave it to you to decide, either rework to convert to
FileDescriptor objects on a per-test basis, or just do a v2 of this
patch with all paths fixed, perhaps for now just fixing this would make
coverity happy :-)

--
Kieran



> Signed-off-by: Umang Jain <email at uajain.com>
> ---
>  test/log/log_api.cpp | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp
> index 33622f8..aeedbf9 100644
> --- a/test/log/log_api.cpp
> +++ b/test/log/log_api.cpp
> @@ -96,6 +96,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);
> 

-- 
Regards
--
Kieran


More information about the libcamera-devel mailing list