From: Karel Zak Date: Wed, 20 Jul 2011 19:15:43 +0000 (+0200) Subject: libmount: cleanup code for "none" source and fstype, fix mem leak X-Git-Tag: v2.20-rc1~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5af0769de62f25f39199fb0df677d185ed8492ce;p=thirdparty%2Futil-linux.git libmount: cleanup code for "none" source and fstype, fix mem leak Signed-off-by: Karel Zak --- diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 86b2423ebb..b00b0ede8d 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -299,17 +299,20 @@ const char *mnt_fs_get_source(struct libmnt_fs *fs) return fs ? fs->source : NULL; } -/* Used by parser struct libmnt_file ONLY (@source has to be allocated) */ +/* + * Used by parser ONLY (@source has to be allocated on error) + */ int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source) { char *t = NULL, *v = NULL; assert(fs); - if (source && !strcmp(source, "none")) + if (source && !strcmp(source, "none")) { + free(source); source = NULL; - if (source && strchr(source, '=')) { + } else if (source && strchr(source, '=')) { if (blkid_parse_tag_string(source, &t, &v) != 0) return -1; } diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 7419f37428..bb4ceef615 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -160,12 +160,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) unmangle_string(fs->target); unmangle_string(fs->vfs_optstr); unmangle_string(fstype); - - if (!strcmp(src, "none")) { - free(src); - src = NULL; - } else - unmangle_string(src); + unmangle_string(src); if (!strcmp(fs->fs_optstr, "none")) { free(fs->fs_optstr); @@ -212,8 +207,7 @@ static int mnt_parse_utab_line(struct libmnt_fs *fs, const char *s) char *v = unmangle(p + 4, &end); if (!v) goto enomem; - if (strcmp(v, "none")) - __mnt_fs_set_source_ptr(fs, v); + __mnt_fs_set_source_ptr(fs, v); } else if (!fs->target && !strncmp(p, "TARGET=", 7)) { fs->target = unmangle(p + 7, &end);