old_e2fsprogs/blkid: close the fd after we are done with it
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 28 Nov 2011 17:57:04 +0000 (18:57 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 28 Nov 2011 17:57:04 +0000 (18:57 +0100)
Some people have HUGE /dev/*...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
e2fsprogs/old_e2fsprogs/blkid/probe.c

index 77bfc737df0265729bc69237fcfd3c768e995291..651193b426f0d680d47210aa3a2902fd71c464a0 100644 (file)
@@ -575,8 +575,12 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
            printf("need to revalidate %s (time since last check %lu)\n",
                   dev->bid_name, diff));
 
-       if (((fd = open(dev->bid_name, O_RDONLY)) < 0) ||
-           (fstat(fd, &st) < 0)) {
+       fd = open(dev->bid_name, O_RDONLY);
+       if (fd < 0
+        || fstat(fd, &st) < 0
+       ) {
+               if (fd >= 0)
+                       close(fd);
                if (errno == ENXIO || errno == ENODEV || errno == ENOENT) {
                        blkid_free_dev(dev);
                        return NULL;
@@ -653,6 +657,7 @@ try_again:
 
        if (!dev->bid_type) {
                blkid_free_dev(dev);
+               close(fd);
                return NULL;
        }