]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: cleanup code for "none" source and fstype, fix mem leak
authorKarel Zak <kzak@redhat.com>
Wed, 20 Jul 2011 19:15:43 +0000 (21:15 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Jul 2011 19:15:43 +0000 (21:15 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/fs.c
libmount/src/tab_parse.c

index 86b2423ebb5723d2d7f2ef5a348402b604e81922..b00b0ede8daac401db383c335fb936de1a3f17c0 100644 (file)
@@ -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;
        }
index 7419f37428b8cb539cb57b818433792836bcb6e9..bb4ceef6157f61b2fb2baafec117664912240013 100644 (file)
@@ -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);