[Ocfs2-tools-devel] [PATCH] debugfs.ocfs2: Fix memory leak problem in process_open_args() & main()
piaojun
piaojun at huawei.com
Sat Feb 14 16:51:45 PST 2015
When I was scanning the code of ocfs2-tools-1.8.4 with valgrind, two memory
leak problems were found in debugfs.ocfs2 tool. The details of the problems
are described below:
1. In process_open_args() , a char pointer 'dev' points to a heap memory
that allocated from strdup(), but the memory was not released at the
end of process_open_args().
2. The similar memory leak problem happens in get_logmode_sysfs(), the
pointer current_mask() should be released after being used.
Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>
---
debugfs.ocfs2/commands.c | 3 ++-
debugfs.ocfs2/main.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index efa7240..1b0b2d9 100755
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -534,7 +534,6 @@ static int process_open_args(char **args,
int num, argc, c;
for (argc = 0; (args[argc]); ++argc);
- dev = strdup(args[1]);
optind = 0;
while ((c = getopt(argc, args, "is:")) != EOF) {
switch (c) {
@@ -564,6 +563,7 @@ static int process_open_args(char **args,
return -1;
}
+ dev = strdup(args[1]);
ret = get_blocksize(dev, byte_off[s-1], &blksize, s);
if (ret) {
com_err(args[0],ret, "Can't get the blocksize from the device"
@@ -575,6 +575,7 @@ static int process_open_args(char **args,
*superblock = byte_off[s-1]/blksize;
ret = 0;
bail:
+ g_free(dev);
return ret;
}
diff --git a/debugfs.ocfs2/main.c b/debugfs.ocfs2/main.c
index cab679f..7463483 100755
--- a/debugfs.ocfs2/main.c
+++ b/debugfs.ocfs2/main.c
@@ -371,7 +371,7 @@ static int get_logmode_sysfs(const char *path, const char *name)
fprintf(stdout, "%s %s", name, current_mask);
}
g_free(logpath);
-
+ g_free(current_mask);
return 0;
}
--
1.8.4.3
More information about the Ocfs2-tools-devel
mailing list