From c125b7cf43aac815782ded0a0f36060e81c79726 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Mon, 15 Jul 2013 19:36:50 +0800 Subject: 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 Signed-off-by: David Sterba Signed-off-by: Chris Mason --- cmds-quota.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'cmds-quota.c') diff --git a/cmds-quota.c b/cmds-quota.c index 2e2971a4..792aa7e2 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) { -- cgit v1.2.3