summaryrefslogtreecommitdiff
path: root/cmds-balance.c
diff options
context:
space:
mode:
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>2013-07-15 19:36:50 +0800
committerDavid Sterba <dsterba@suse.cz>2013-08-09 14:32:36 +0200
commitc125b7cf43aac815782ded0a0f36060e81c79726 (patch)
tree6d954a3f9e39f834bc96643bf5c574bdc9cea00e /cmds-balance.c
parentc118c21b3e855c37c01db4be5746055629b70a19 (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-balance.c')
-rw-r--r--cmds-balance.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/cmds-balance.c b/cmds-balance.c
index cffa807a..c78b7261 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -294,8 +294,9 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
return 12;
@@ -339,7 +340,7 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
}
out:
- close(fd);
+ close_file_or_dir(fd, dirstream);
return ret;
}
@@ -487,13 +488,14 @@ static int cmd_balance_pause(int argc, char **argv)
int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
usage(cmd_balance_pause_usage);
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
return 12;
@@ -501,7 +503,7 @@ static int cmd_balance_pause(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_PAUSE);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
fprintf(stderr, "ERROR: balance pause on '%s' failed - %s\n",
@@ -524,13 +526,14 @@ static int cmd_balance_cancel(int argc, char **argv)
int fd;
int ret;
int e;
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
usage(cmd_balance_cancel_usage);
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
return 12;
@@ -538,7 +541,7 @@ static int cmd_balance_cancel(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_CANCEL);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
fprintf(stderr, "ERROR: balance cancel on '%s' failed - %s\n",
@@ -559,6 +562,7 @@ static int cmd_balance_resume(int argc, char **argv)
{
struct btrfs_ioctl_balance_args args;
const char *path;
+ DIR *dirstream = NULL;
int fd;
int ret;
int e;
@@ -568,7 +572,7 @@ static int cmd_balance_resume(int argc, char **argv)
path = argv[1];
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access to '%s'\n", path);
return 12;
@@ -579,7 +583,7 @@ static int cmd_balance_resume(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
if (e == ECANCELED) {
@@ -626,6 +630,7 @@ static int cmd_balance_status(int argc, char **argv)
{
struct btrfs_ioctl_balance_args args;
const char *path;
+ DIR *dirstream = NULL;
int fd;
int verbose = 0;
int ret;
@@ -657,7 +662,7 @@ static int cmd_balance_status(int argc, char **argv)
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 to '%s'\n", path);
return 2;
@@ -665,7 +670,7 @@ static int cmd_balance_status(int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
if (e == ENOTCONN) {