mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-25 07:32:22 +00:00
btrfs-progs: free strdup()s that are not freed
The strdup()s not freed are reported as memory leaks by valgrind. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
aea22fa1b5
commit
1c87a95bfc
@ -75,6 +75,8 @@ static int cmd_subvol_create(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int retval, res, len;
|
int retval, res, len;
|
||||||
int fddst = -1;
|
int fddst = -1;
|
||||||
|
char *dupname = NULL;
|
||||||
|
char *dupdir = NULL;
|
||||||
char *newname;
|
char *newname;
|
||||||
char *dstdir;
|
char *dstdir;
|
||||||
char *dst;
|
char *dst;
|
||||||
@ -119,10 +121,10 @@ static int cmd_subvol_create(int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
newname = strdup(dst);
|
dupname = strdup(dst);
|
||||||
newname = basename(newname);
|
newname = basename(dupname);
|
||||||
dstdir = strdup(dst);
|
dupdir = strdup(dst);
|
||||||
dstdir = dirname(dstdir);
|
dstdir = dirname(dupdir);
|
||||||
|
|
||||||
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
||||||
strchr(newname, '/') ){
|
strchr(newname, '/') ){
|
||||||
@ -174,6 +176,8 @@ static int cmd_subvol_create(int argc, char **argv)
|
|||||||
out:
|
out:
|
||||||
close_file_or_dir(fddst, dirstream);
|
close_file_or_dir(fddst, dirstream);
|
||||||
free(inherit);
|
free(inherit);
|
||||||
|
free(dupname);
|
||||||
|
free(dupdir);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -208,6 +212,8 @@ static int cmd_subvol_delete(int argc, char **argv)
|
|||||||
int res, fd, len, e, cnt = 1, ret = 0;
|
int res, fd, len, e, cnt = 1, ret = 0;
|
||||||
struct btrfs_ioctl_vol_args args;
|
struct btrfs_ioctl_vol_args args;
|
||||||
char *dname, *vname, *cpath;
|
char *dname, *vname, *cpath;
|
||||||
|
char *dupdname = NULL;
|
||||||
|
char *dupvname = NULL;
|
||||||
char *path;
|
char *path;
|
||||||
DIR *dirstream = NULL;
|
DIR *dirstream = NULL;
|
||||||
|
|
||||||
@ -230,10 +236,10 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cpath = realpath(path, NULL);
|
cpath = realpath(path, NULL);
|
||||||
dname = strdup(cpath);
|
dupdname = strdup(cpath);
|
||||||
dname = dirname(dname);
|
dname = dirname(dupdname);
|
||||||
vname = strdup(cpath);
|
dupvname = strdup(cpath);
|
||||||
vname = basename(vname);
|
vname = basename(dupvname);
|
||||||
free(cpath);
|
free(cpath);
|
||||||
|
|
||||||
if (!strcmp(vname, ".") || !strcmp(vname, "..") ||
|
if (!strcmp(vname, ".") || !strcmp(vname, "..") ||
|
||||||
@ -274,6 +280,8 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
free(dupdname);
|
||||||
|
free(dupvname);
|
||||||
cnt++;
|
cnt++;
|
||||||
if (cnt < argc)
|
if (cnt < argc)
|
||||||
goto again;
|
goto again;
|
||||||
@ -494,6 +502,8 @@ static int cmd_snapshot(int argc, char **argv)
|
|||||||
int res, retval;
|
int res, retval;
|
||||||
int fd = -1, fddst = -1;
|
int fd = -1, fddst = -1;
|
||||||
int len, readonly = 0;
|
int len, readonly = 0;
|
||||||
|
char *dupname = NULL;
|
||||||
|
char *dupdir = NULL;
|
||||||
char *newname;
|
char *newname;
|
||||||
char *dstdir;
|
char *dstdir;
|
||||||
struct btrfs_ioctl_vol_args_v2 args;
|
struct btrfs_ioctl_vol_args_v2 args;
|
||||||
@ -561,14 +571,14 @@ static int cmd_snapshot(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
newname = strdup(subvol);
|
dupname = strdup(subvol);
|
||||||
newname = basename(newname);
|
newname = basename(dupname);
|
||||||
dstdir = dst;
|
dstdir = dst;
|
||||||
} else {
|
} else {
|
||||||
newname = strdup(dst);
|
dupname = strdup(dst);
|
||||||
newname = basename(newname);
|
newname = basename(dupname);
|
||||||
dstdir = strdup(dst);
|
dupdir = strdup(dst);
|
||||||
dstdir = dirname(dstdir);
|
dstdir = dirname(dupdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
||||||
@ -628,6 +638,8 @@ out:
|
|||||||
close_file_or_dir(fddst, dirstream1);
|
close_file_or_dir(fddst, dirstream1);
|
||||||
close_file_or_dir(fd, dirstream2);
|
close_file_or_dir(fd, dirstream2);
|
||||||
free(inherit);
|
free(inherit);
|
||||||
|
free(dupname);
|
||||||
|
free(dupdir);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user