summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2013-02-25 16:54:49 -0600
committerDavid Sterba <dsterba@suse.cz>2013-02-27 14:40:05 +0100
commitfb631862c98bbed777026597ef73b3194da69892 (patch)
tree2a8448d5aa21bc80c5f3700356c8483b87b487a0 /cmds-subvolume.c
parent917609b8d6d99dcad158fd7d7fe3deffeca0d68e (diff)
btrfs-progs: fix fd leak in cmd_subvol_set_default
Rearrange cmd_subvol_set_default() slightly so we don't have to close the fd on an error return. While we're at it, fix whitespace & remove magic return values. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 0dfaefe5..461eed90 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -712,24 +712,25 @@ static int cmd_subvol_set_default(int argc, char **argv)
subvolid = argv[1];
path = argv[2];
+ objectid = (unsigned long long)strtoll(subvolid, NULL, 0);
+ if (errno == ERANGE) {
+ fprintf(stderr, "ERROR: invalid tree id (%s)\n", subvolid);
+ return 1;
+ }
+
fd = open_file_or_dir(path);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
- return 12;
+ return 1;
}
- objectid = (unsigned long long)strtoll(subvolid, NULL, 0);
- if (errno == ERANGE) {
- fprintf(stderr, "ERROR: invalid tree id (%s)\n",subvolid);
- return 30;
- }
ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
e = errno;
close(fd);
- if( ret < 0 ){
+ if (ret < 0) {
fprintf(stderr, "ERROR: unable to set a new default subvolume - %s\n",
strerror(e));
- return 30;
+ return 1;
}
return 0;
}