summaryrefslogtreecommitdiff
path: root/cmds-quota.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-quota.c
parentc118c21b3e855c37c01db4be5746055629b70a19 (diff)
downloadbtrfs-progs-c125b7cf43aac815782ded0a0f36060e81c79726.tar.gz
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-quota.c')
-rw-r--r--cmds-quota.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/cmds-quota.c b/cmds-quota.c
index 2e2971a..792aa7e 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -37,6 +37,7 @@ int quota_ctl(int cmd, int argc, char **argv)
int e;
char *path = argv[1];
struct btrfs_ioctl_quota_ctl_args args;
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 2))
return -1;
@@ -44,7 +45,7 @@ int quota_ctl(int cmd, int argc, char **argv)
memset(&args, 0, sizeof(args));
args.cmd = cmd;
- fd = open_file_or_dir(path);
+ fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", path);
return 12;
@@ -52,7 +53,7 @@ int quota_ctl(int cmd, int argc, char **argv)
ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ret < 0) {
fprintf(stderr, "ERROR: quota command failed: %s\n",
strerror(e));
@@ -108,6 +109,7 @@ static int cmd_quota_rescan(int argc, char **argv)
char *path = NULL;
struct btrfs_ioctl_quota_rescan_args args;
int ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
+ DIR *dirstream = NULL;
optind = 1;
while (1) {
@@ -129,7 +131,7 @@ static int cmd_quota_rescan(int argc, char **argv)
memset(&args, 0, sizeof(args));
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'\n", path);
return 12;
@@ -137,7 +139,7 @@ static int cmd_quota_rescan(int argc, char **argv)
ret = ioctl(fd, ioctlnum, &args);
e = errno;
- close(fd);
+ close_file_or_dir(fd, dirstream);
if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN) {
if (ret < 0) {