diff options
author | Karel Zak | 2012-01-26 14:42:35 +0100 |
---|---|---|
committer | Karel Zak | 2012-01-26 14:42:35 +0100 |
commit | 53d911347d242b2c2bc6c6eff1174bae8c83bd67 (patch) | |
tree | c744c1037c6e43c277a8005ac6a0ab3d65702308 /libmount/src/tab_parse.c | |
parent | tests: add valgrind to libmount tab parse test (diff) | |
download | kernel-qcow2-util-linux-53d911347d242b2c2bc6c6eff1174bae8c83bd67.tar.gz kernel-qcow2-util-linux-53d911347d242b2c2bc6c6eff1174bae8c83bd67.tar.xz kernel-qcow2-util-linux-53d911347d242b2c2bc6c6eff1174bae8c83bd67.zip |
libmount: fix leak in tab parsing error code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r-- | libmount/src/tab_parse.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 8c5b23c29..0f618bb32 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -82,18 +82,28 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, char *s) if (optstr && *optstr) unmangle_string(optstr); + /* note that __foo functions does not reallocate the string + */ rc = __mnt_fs_set_source_ptr(fs, src); - if (!rc) + if (!rc) { + src = NULL; rc = __mnt_fs_set_fstype_ptr(fs, fstype); + if (!rc) + fstype = NULL; + } if (!rc && optstr) rc = mnt_fs_set_options(fs, optstr); free(optstr); + optstr = NULL; } else { DBG(TAB, mnt_debug("tab parse error: [sscanf rc=%d]: '%s'", rc, s)); rc = -EINVAL; } if (rc) { + free(src); + free(fstype); + free(optstr); DBG(TAB, mnt_debug("tab parse error: [set vars, rc=%d]\n", rc)); return rc; /* error */ } @@ -124,7 +134,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) { int rc, end = 0; unsigned int maj, min; - char *fstype, *src, *p; + char *fstype = NULL, *src = NULL, *p; rc = sscanf(s, "%u " /* (1) id */ "%u " /* (2) parent */ @@ -178,14 +188,20 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) unmangle_string(fs->fs_optstr); rc = __mnt_fs_set_fstype_ptr(fs, fstype); - if (!rc) + if (!rc) { + fstype = NULL; rc = __mnt_fs_set_source_ptr(fs, src); + if (!rc) + src = NULL; + } /* merge VFS and FS options to the one string */ fs->optstr = mnt_fs_strdup_options(fs); if (!fs->optstr) rc = -ENOMEM; } else { + free(fstype); + free(src); DBG(TAB, mnt_debug( "mountinfo parse error [sscanf rc=%d]: '%s'", rc, s)); rc = -EINVAL; |