Re: [PATCH] xfs_io: don't leak fd in open -Tr failure case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/27/14, 2:25 PM, Eric Sandeen wrote:
> Coverity spotted this.
> 
> It complained that we didn't close the fd before returning in
> this case of incompatible options, but it seems like we should
> just test for the incompatible flags before even trying to open
> the file, no?
> 
> (The open would have failed in any case, but with a somewhat
> cryptic "Invalid argument" - so it's probably better to state
> it plainly and bail immediately.)

So actually, we wouldn't leak, because the open would fail.
So I guess it's not the best subject & description...

-Eric

> Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
> ---
> 
> diff --git a/io/open.c b/io/open.c
> index 6bb0d46..c106fa7 100644
> --- a/io/open.c
> +++ b/io/open.c
> @@ -342,6 +342,11 @@ open_f(
>  	if (optind != argc - 1)
>  		return command_usage(&open_cmd);
>  
> +	if ((flags & (IO_READONLY|IO_TMPFILE)) == (IO_READONLY|IO_TMPFILE)) {
> +		fprintf(stderr, _("-T and -r options are incompatible\n"));
> +		return -1;
> +	}
> +
>  	fd = openfile(argv[optind], &geometry, flags, mode);
>  	if (fd < 0)
>  		return 0;
> @@ -349,11 +354,6 @@ open_f(
>  	if (!platform_test_xfs_fd(fd))
>  		flags |= IO_FOREIGN;
>  
> -	if ((flags & (IO_READONLY|IO_TMPFILE)) == (IO_READONLY|IO_TMPFILE)) {
> -		fprintf(stderr, _("-T and -r options are incompatible\n"));
> -		return -1;
> -	}
> -
>  	addfile(argv[optind], fd, &geometry, flags);
>  	return 0;
>  }
> 
> _______________________________________________
> xfs mailing list
> xfs@xxxxxxxxxxx
> http://oss.sgi.com/mailman/listinfo/xfs
> 

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs




[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux