summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Brown <zab@redhat.com>2013-01-23 15:11:24 -0800
committerZach Brown <zab@redhat.com>2013-02-05 16:09:40 -0800
commit4cce2094b18ab674c707d5c9f747d71874076d2c (patch)
tree8f869083f4ad0161e15e96358715d409e0228ea0
parent4e381d4169fbc31a81ffa7fab267b5a51814d021 (diff)
btrfs-progs: don't leak fd in resize
Argument validation failed to close the fd that was opened. So check the arguments before opening anything. Signed-off-by: Zach Brown <zab@redhat.com>
-rw-r--r--cmds-filesystem.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 507239ad..045c896f 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -464,11 +464,6 @@ static int cmd_resize(int argc, char **argv)
amount = argv[1];
path = argv[2];
- fd = open_file_or_dir(path);
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
- }
len = strlen(amount);
if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
fprintf(stderr, "ERROR: size value too long ('%s)\n",
@@ -476,6 +471,12 @@ static int cmd_resize(int argc, char **argv)
return 14;
}
+ fd = open_file_or_dir(path);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access to '%s'\n", path);
+ return 12;
+ }
+
printf("Resize '%s' of '%s'\n", path, amount);
strncpy(args.name, amount, BTRFS_PATH_NAME_MAX);
args.name[BTRFS_PATH_NAME_MAX-1] = 0;