]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: Fix file descriptor leaks in libubi
authorDaniel van Gerpen <daniel@vangerpen.de>
Sat, 29 Mar 2014 23:52:10 +0000 (00:52 +0100)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 31 Mar 2014 09:52:38 +0000 (12:52 +0300)
Amended by Artem.

Signed-off-by: Daniel van Gerpen <daniel@vangerpen.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
ubi-utils/libubi.c

index 598191e0235b37ecd42e14ca5788352e91a76109..1e08b7d121dbd7d827899638d323f2616656386d 100644 (file)
@@ -188,10 +188,8 @@ static int read_data(const char *file, void *buf, int buf_len)
                goto out_error;
        }
 
-       if (close(fd)) {
-               sys_errmsg("close failed on \"%s\"", file);
-               return -1;
-       }
+       if (close(fd))
+               return sys_errmsg("close failed on \"%s\"", file);
 
        return rd;
 
@@ -420,6 +418,9 @@ static int vol_node2nums(struct libubi *lib, const char *node, int *dev_num,
                return -1;
        }
 
+       if (close(fd))
+               return sys_errmsg("close failed on \"%s\"", file);
+
        *dev_num = i;
        *vol_id = minor - 1;
        errno = 0;
@@ -911,6 +912,9 @@ int ubi_probe_node(libubi_t desc, const char *node)
        if (fd == -1)
                goto out_not_ubi;
 
+        if (close(fd))
+               sys_errmsg("close failed on \"%s\"", file);
+
        return 2;
 
 out_not_ubi: