diff options
author | Wang Shilong <wangsl.fnst@cn.fujitsu.com> | 2013-07-15 19:36:50 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-08-09 14:32:36 +0200 |
commit | c125b7cf43aac815782ded0a0f36060e81c79726 (patch) | |
tree | 6d954a3f9e39f834bc96643bf5c574bdc9cea00e /cmds-device.c | |
parent | c118c21b3e855c37c01db4be5746055629b70a19 (diff) |
Btrfs-progs: fix closing of opendir()
valgrind complains open_file_or_dir() causes a memory leak.That is because
if we open a directoy by opendir(), and then we should call closedir()
to free memory.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'cmds-device.c')
-rw-r--r-- | cmds-device.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/cmds-device.c b/cmds-device.c index 9e7328b2..3a694beb 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -54,13 +54,14 @@ static int cmd_add_dev(int argc, char **argv) { char *mntpnt; int i, fdmnt, ret=0, e; + DIR *dirstream = NULL; if (check_argc_min(argc, 3)) usage(cmd_add_dev_usage); mntpnt = argv[argc - 1]; - fdmnt = open_file_or_dir(mntpnt); + fdmnt = open_file_or_dir(mntpnt, &dirstream); if (fdmnt < 0) { fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt); return 12; @@ -127,7 +128,7 @@ static int cmd_add_dev(int argc, char **argv) } - close(fdmnt); + close_file_or_dir(fdmnt, dirstream); if (ret) return ret+20; else @@ -144,13 +145,14 @@ static int cmd_rm_dev(int argc, char **argv) { char *mntpnt; int i, fdmnt, ret=0, e; + DIR *dirstream = NULL; if (check_argc_min(argc, 3)) usage(cmd_rm_dev_usage); mntpnt = argv[argc - 1]; - fdmnt = open_file_or_dir(mntpnt); + fdmnt = open_file_or_dir(mntpnt, &dirstream); if (fdmnt < 0) { fprintf(stderr, "ERROR: can't access to '%s'\n", mntpnt); return 12; @@ -170,7 +172,7 @@ static int cmd_rm_dev(int argc, char **argv) } } - close(fdmnt); + close_file_or_dir(fdmnt, dirstream); if( ret) return ret+20; else @@ -297,6 +299,7 @@ static int cmd_dev_stats(int argc, char **argv) int c; int err = 0; __u64 flags = 0; + DIR *dirstream = NULL; optind = 1; while ((c = getopt(argc, argv, "z")) != -1) { @@ -321,7 +324,7 @@ static int cmd_dev_stats(int argc, char **argv) path = argv[optind]; - fdmnt = open_path_or_dev_mnt(path); + fdmnt = open_path_or_dev_mnt(path, &dirstream); if (fdmnt < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); @@ -389,7 +392,7 @@ static int cmd_dev_stats(int argc, char **argv) out: free(di_args); - close(fdmnt); + close_file_or_dir(fdmnt, dirstream); return err; } |