[PATCH 2/2] mkfs.xfs: prevent close(-1) on protofile error path
Mark Tinguely
tinguely at sgi.com
Mon Apr 14 10:01:58 CDT 2014
On 04/14/14 09:48, Eric Sandeen wrote:
> My previous cleanups introduced this; in the case where
> fd=open() failed, the out_fail: path would try to close(-1).
>
> Signed-off-by: Eric Sandeen<sandeen at redhat.com>
> ---
>
> diff --git a/mkfs/proto.c b/mkfs/proto.c
> index 308325b..5a47e27 100644
> --- a/mkfs/proto.c
> +++ b/mkfs/proto.c
> @@ -84,7 +84,8 @@ setup_proto(
> return buf;
>
> out_fail:
> - close(fd);
> + if (fd>= 0)
> + close(fd);
> free(buf);
> exit(1);
> }
>
I would have bypassed the close with a new open error goto, but this
does the trick as well.
Reviewed-by: Mark Tinguely <tinguely at sgi.com>
More information about the xfs
mailing list