From: Masatake YAMATO <yamato@redhat.com>
To: util-linux@vger.kernel.org
Subject: [PATCH] Fix a potential memory leak at mnt_table_parse_dir
Date: Fri, 20 Jan 2012 13:00:34 +0900 (JST) [thread overview]
Message-ID: <20120120.130034.1018682633157048125.yamato@redhat.com> (raw)
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
next reply other threads:[~2012-01-20 4:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-20 4:00 Masatake YAMATO [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120120.130034.1018682633157048125.yamato@redhat.com \
--to=yamato@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).