xfs
[Top] [All Lists]

Re: [PATCH 2/2] mkfs.xfs: prevent close(-1) on protofile error path

To: Eric Sandeen <sandeen@xxxxxxxxxxx>
Subject: Re: [PATCH 2/2] mkfs.xfs: prevent close(-1) on protofile error path
From: Mark Tinguely <tinguely@xxxxxxx>
Date: Mon, 14 Apr 2014 10:01:58 -0500
Cc: xfs-oss <xfs@xxxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <534BF53C.4000706@xxxxxxxxxxx>
References: <534BF472.8030908@xxxxxxxxxxx> <534BF53C.4000706@xxxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:9.0) Gecko/20120122 Thunderbird/9.0
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@xxxxxxxxxx>
---

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@xxxxxxx>

<Prev in Thread] Current Thread [Next in Thread>