]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix a potential memory leak at mnt_table_parse_dir
authorMasatake YAMATO <yamato@redhat.com>
Fri, 20 Jan 2012 04:00:34 +0000 (13:00 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jan 2012 12:54:03 +0000 (13:54 +0100)
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

index bbdea553c7829fca138abf6dd4513f25bc036dd7..369325db1349cd7ba6d8722fc0eac4e2227c58c8 100644 (file)
@@ -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