Add some close(fd) when error occures in mkfs.
And add close(fd) when end use it.
Signed-off-by: Gu Jinxiang <gujx@xxxxxxxxxxxxxx>
---
mkfs/main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mkfs/main.c b/mkfs/main.c
index 2b109a5..ec82565 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1694,6 +1694,7 @@ int main(int argc, char **argv)
file,
(unsigned long long)block_count,
(unsigned long long)dev_block_count);
+ close(fd);
exit(1);
}
} else {
@@ -1711,6 +1712,7 @@ int main(int argc, char **argv)
ret = zero_output_file(fd, block_count);
if (ret) {
error("unable to zero the output file");
+ close(fd);
exit(1);
}
/* our "device" is the new image file */
@@ -1721,6 +1723,7 @@ int main(int argc, char **argv)
if (dev_block_count < BTRFS_MKFS_SYSTEM_GROUP_SIZE) {
error("device is too small to make filesystem, must be at least %llu",
(unsigned long long)BTRFS_MKFS_SYSTEM_GROUP_SIZE);
+ close(fd);
exit(1);
}
@@ -1740,6 +1743,7 @@ int main(int argc, char **argv)
ret = make_btrfs(fd, &mkfs_cfg);
if (ret) {
error("error during mkfs: %s", strerror(-ret));
+ close(fd);
exit(1);
}
@@ -1750,6 +1754,7 @@ int main(int argc, char **argv)
close(fd);
exit(1);
}
+ close(fd);
root = fs_info->fs_root;
fs_info->alloc_start = alloc_start;
@@ -1827,6 +1832,7 @@ int main(int argc, char **argv)
sectorsize, sectorsize, sectorsize);
if (ret) {
error("unable to add %s to filesystem: %d", file, ret);
+ close(fd);
goto out;
}
if (verbose >= 2) {
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html