btrfs-progs: don't leak fd in test_dev_for_mkfs() error paths
[platform/upstream/btrfs-progs.git] / utils.c
diff --git a/utils.c b/utils.c
index 47ba23b..9af49f7 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1928,10 +1928,12 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr)
        if (fstat(fd, &st)) {
                snprintf(estr, sz, "unable to stat %s: %s\n", file,
                        strerror(errno));
+               close(fd);
                return 1;
        }
        if (!S_ISBLK(st.st_mode)) {
                fprintf(stderr, "'%s' is not a block device\n", file);
+               close(fd);
                return 1;
        }
        close(fd);