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-replace.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-replace.c')
-rw-r--r-- | cmds-replace.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/cmds-replace.c b/cmds-replace.c index 6397bb5d..5d3c2f01 100644 --- a/cmds-replace.c +++ b/cmds-replace.c @@ -143,6 +143,7 @@ static int cmd_start_replace(int argc, char **argv) u64 dstdev_block_count; int do_not_background = 0; int mixed = 0; + DIR *dirstream = NULL; while ((c = getopt(argc, argv, "Brf")) != -1) { switch (c) { @@ -169,7 +170,7 @@ static int cmd_start_replace(int argc, char **argv) usage(cmd_start_replace_usage); path = argv[optind + 2]; - 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\": %s\n", @@ -336,7 +337,7 @@ static int cmd_start_replace(int argc, char **argv) goto leave_with_error; } } - close(fdmnt); + close_file_or_dir(fdmnt, dirstream); return 0; leave_with_error: @@ -367,6 +368,7 @@ static int cmd_status_replace(int argc, char **argv) char *path; int once = 0; int ret; + DIR *dirstream = NULL; while ((c = getopt(argc, argv, "1")) != -1) { switch (c) { @@ -383,7 +385,7 @@ static int cmd_status_replace(int argc, char **argv) usage(cmd_status_replace_usage); path = argv[optind]; - fd = open_file_or_dir(path); + fd = open_file_or_dir(path, &dirstream); e = errno; if (fd < 0) { fprintf(stderr, "ERROR: can't access \"%s\": %s\n", @@ -392,7 +394,7 @@ static int cmd_status_replace(int argc, char **argv) } ret = print_replace_status(fd, path, once); - close(fd); + close_file_or_dir(fd, dirstream); return ret; } @@ -533,6 +535,7 @@ static int cmd_cancel_replace(int argc, char **argv) int fd; int e; char *path; + DIR *dirstream = NULL; while ((c = getopt(argc, argv, "")) != -1) { switch (c) { @@ -546,7 +549,7 @@ static int cmd_cancel_replace(int argc, char **argv) usage(cmd_cancel_replace_usage); path = argv[optind]; - fd = open_file_or_dir(path); + fd = open_file_or_dir(path, &dirstream); if (fd < 0) { fprintf(stderr, "ERROR: can't access \"%s\": %s\n", path, strerror(errno)); @@ -556,7 +559,7 @@ static int cmd_cancel_replace(int argc, char **argv) args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL; ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args); e = errno; - close(fd); + close_file_or_dir(fd, dirstream); if (ret) { fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %s, %s\n", path, strerror(e), |