summaryrefslogtreecommitdiff
path: root/cmds-inspect.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-inspect.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-inspect.c')
-rw-r--r--cmds-inspect.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c
index 30b41fc..231819d 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -92,6 +92,7 @@ static int cmd_inode_resolve(int argc, char **argv)
int fd;
int verbose = 0;
int ret;
+ DIR *dirstream = NULL;
optind = 1;
while (1) {
@@ -111,7 +112,7 @@ static int cmd_inode_resolve(int argc, char **argv)
if (check_argc_exact(argc - optind, 2))
usage(cmd_inode_resolve_usage);
- fd = open_file_or_dir(argv[optind+1]);
+ fd = open_file_or_dir(argv[optind+1], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]);
return 12;
@@ -119,7 +120,7 @@ static int cmd_inode_resolve(int argc, char **argv)
ret = __ino_to_path_fd(atoll(argv[optind]), fd, verbose,
argv[optind+1]);
- close(fd);
+ close_file_or_dir(fd, dirstream);
return ret;
}
@@ -148,6 +149,7 @@ static int cmd_logical_resolve(int argc, char **argv)
u64 size = 4096;
char full_path[4096];
char *path_ptr;
+ DIR *dirstream = NULL;
optind = 1;
while (1) {
@@ -183,7 +185,7 @@ static int cmd_logical_resolve(int argc, char **argv)
loi.size = size;
loi.inodes = (uintptr_t)inodes;
- fd = open_file_or_dir(argv[optind+1]);
+ fd = open_file_or_dir(argv[optind+1], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[optind+1]);
ret = 12;
@@ -216,6 +218,7 @@ static int cmd_logical_resolve(int argc, char **argv)
u64 root = inodes->val[i+2];
int path_fd;
char *name;
+ DIR *dirs = NULL;
if (getpath) {
name = btrfs_list_path_for_root(fd, root);
@@ -232,7 +235,7 @@ static int cmd_logical_resolve(int argc, char **argv)
name);
BUG_ON(ret >= bytes_left);
free(name);
- path_fd = open_file_or_dir(full_path);
+ path_fd = open_file_or_dir(full_path, &dirs);
if (path_fd < 0) {
fprintf(stderr, "ERROR: can't access "
"'%s'\n", full_path);
@@ -241,7 +244,7 @@ static int cmd_logical_resolve(int argc, char **argv)
}
__ino_to_path_fd(inum, path_fd, verbose, full_path);
if (path_fd != fd)
- close(path_fd);
+ close_file_or_dir(path_fd, dirs);
} else {
printf("inode %llu offset %llu root %llu\n", inum,
offset, root);
@@ -249,8 +252,7 @@ static int cmd_logical_resolve(int argc, char **argv)
}
out:
- if (fd >= 0)
- close(fd);
+ close_file_or_dir(fd, dirstream);
free(inodes);
return ret;
}
@@ -267,11 +269,12 @@ static int cmd_subvolid_resolve(int argc, char **argv)
int fd = -1;
u64 subvol_id;
char path[BTRFS_PATH_NAME_MAX + 1];
+ DIR *dirstream = NULL;
if (check_argc_exact(argc, 3))
usage(cmd_subvolid_resolve_usage);
- fd = open_file_or_dir(argv[2]);
+ fd = open_file_or_dir(argv[2], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", argv[2]);
ret = -ENOENT;
@@ -292,8 +295,7 @@ static int cmd_subvolid_resolve(int argc, char **argv)
printf("%s\n", path);
out:
- if (fd >= 0)
- close(fd);
+ close_file_or_dir(fd, dirstream);
return ret ? 1 : 0;
}