]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: make fd usage in md code more robust
authorKarel Zak <kzak@redhat.com>
Tue, 31 Jan 2012 13:56:34 +0000 (14:56 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 31 Jan 2012 13:56:34 +0000 (14:56 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/topology/md.c

index d1405546583b0ec3c64d722c6a31668ded828baf..a24fbaca62b89ff35c28cc2a86fbe2057950626d 100644 (file)
@@ -109,8 +109,10 @@ static int probe_md_tp(blkid_probe pr,
        if (ioctl(fd, GET_ARRAY_INFO, &md))
                goto nothing;
 
-       if (fd != pr->fd)
+       if (fd >= 0 && fd != pr->fd) {
                close(fd);
+               fd = -1;
+       }
 
        /*
         * Ignore levels we don't want aligned (e.g. linear)
@@ -138,7 +140,7 @@ static int probe_md_tp(blkid_probe pr,
        return 0;
 
 nothing:
-       if (fd != -1 && fd != pr->fd)
+       if (fd >= 0 && fd != pr->fd)
                close(fd);
        return 1;
 }