aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-receive.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-06-09 14:58:43 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-09 14:58:43 +0200
commitf51b76109f6be2bfee3e4eec61ae3f9bc3d7f8e2 (patch)
tree4cd4ed849c64f1b76ace65810d118594ce1623f6 /cmds-receive.c
parentadd9d7fe4b0f0f856adc4fd390350d807204f70c (diff)
downloadbtrfs-progs-f51b76109f6be2bfee3e4eec61ae3f9bc3d7f8e2.tar.gz
btrfs-progs-f51b76109f6be2bfee3e4eec61ae3f9bc3d7f8e2.tar.xz
btrfs-progs-f51b76109f6be2bfee3e4eec61ae3f9bc3d7f8e2.zip
btrfs-progs: receive: fix minor resource leak
Resolves-coverity-id: 1302985 Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-receive.c')
-rw-r--r--cmds-receive.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/cmds-receive.c b/cmds-receive.c
index 114b718..a57f8d9 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -1002,7 +1002,7 @@ int cmd_receive(int argc, char **argv)
struct btrfs_receive r;
int receive_fd = fileno(stdin);
u64 max_errors = 1;
- int ret;
+ int ret = 0;
memset(&r, 0, sizeof(r));
r.mnt_fd = -1;
@@ -1039,10 +1039,11 @@ int cmd_receive(int argc, char **argv)
max_errors = arg_strtou64(optarg);
break;
case 'm':
+ free(realmnt);
realmnt = strdup(optarg);
if (!realmnt) {
fprintf(stderr, "ERROR: couldn't allocate realmnt.\n");
- return 1;
+ goto out;
}
break;
case '?':
@@ -1061,12 +1062,15 @@ int cmd_receive(int argc, char **argv)
receive_fd = open(fromfile, O_RDONLY | O_NOATIME);
if (receive_fd < 0) {
fprintf(stderr, "ERROR: failed to open %s\n", fromfile);
- return 1;
+ goto out;
}
}
ret = do_receive(&r, tomnt, realmnt, receive_fd, max_errors);
+out:
+ free(realmnt);
+
return !!ret;
}