* [PATCH] Fix a potential memory leak at mnt_table_parse_dir
@ 2012-01-20 4:00 Masatake YAMATO
2012-01-20 9:34 ` memory leaks tests (Re: [PATCH] Fix a potential memory leak at mnt_table_parse_dir) Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Masatake YAMATO @ 2012-01-20 4:00 UTC (permalink / raw)
To: util-linux
mnt_table_parse_dir in libmount/src/tab_parse.c calls
scandir, and then opendir. When the latter one, opendir is failed,
buffers allocated in scandir are not released.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
libmount/src/tab_parse.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index 6cd66af..33aa7ef 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -431,7 +431,7 @@ int mnt_table_parse_file(struct libmnt_table *tb, const char *filename)
static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
{
- int n = 0, i;
+ int n = 0, i, r = 0;
DIR *dir = NULL;
struct dirent **namelist = NULL;
@@ -443,8 +443,10 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
/* let use "at" functions rather than play crazy games with paths... */
dir = opendir(dirname);
- if (!dir)
- return -errno;
+ if (!dir) {
+ r = -errno;
+ goto out;
+ }
for (i = 0; i < n; i++) {
struct dirent *d = namelist[i];
@@ -480,12 +482,13 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
}
}
+out:
for (i = 0; i < n; i++)
free(namelist[i]);
free(namelist);
if (dir)
closedir(dir);
- return 0;
+ return r;
}
struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt)
--
1.7.7.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* memory leaks tests (Re: [PATCH] Fix a potential memory leak at mnt_table_parse_dir)
2012-01-20 4:00 [PATCH] Fix a potential memory leak at mnt_table_parse_dir Masatake YAMATO
@ 2012-01-20 9:34 ` Karel Zak
2012-01-30 11:08 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2012-01-20 9:34 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: util-linux
On Fri, Jan 20, 2012 at 01:00:34PM +0900, Masatake YAMATO wrote:
> mnt_table_parse_dir in libmount/src/tab_parse.c calls
> scandir, and then opendir. When the latter one, opendir is failed,
> buffers allocated in scandir are not released.
Thanks, I'll apply the patch.
BTW, it's possible to compile some test binaries by:
make -C libmount/src tests
these programs are used in tests/ts/libmount regression tests.
It would be nice to add valgrind (or so) to the tests and check for
mem-leaks. (Ideally add some simple infrastructure to tests/functions.sh
and log valgrind output to "$TS_OUTPUT.mem".) Volunteer? ;-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-30 11:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-20 4:00 [PATCH] Fix a potential memory leak at mnt_table_parse_dir Masatake YAMATO
2012-01-20 9:34 ` memory leaks tests (Re: [PATCH] Fix a potential memory leak at mnt_table_parse_dir) Karel Zak
2012-01-30 11:08 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).