summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_parse.c
diff options
context:
space:
mode:
authorMasatake YAMATO2012-01-20 05:00:34 +0100
committerKarel Zak2012-01-23 13:54:03 +0100
commitb28890b04185676354b38d5443109d196f95d2d8 (patch)
tree1cd58340c97f02355376e0e0ed5b813952ca8f0e /libmount/src/tab_parse.c
parentlibmount: Use filter arg of scandir* to pickup /etc/fstab.d/*.fstab files (diff)
downloadkernel-qcow2-util-linux-b28890b04185676354b38d5443109d196f95d2d8.tar.gz
kernel-qcow2-util-linux-b28890b04185676354b38d5443109d196f95d2d8.tar.xz
kernel-qcow2-util-linux-b28890b04185676354b38d5443109d196f95d2d8.zip
libmount: fix a potential memory leak at mnt_table_parse_dir
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>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r--libmount/src/tab_parse.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index bbdea553c..369325db1 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -501,7 +501,7 @@ static int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
#else
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;
@@ -511,8 +511,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];
@@ -531,12 +533,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;
}
#endif