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>
This commit is contained in:
Zach Brown 2013-01-23 15:11:24 -08:00
parent 4e381d4169
commit 4cce2094b1

View File

@ -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;