[PATCH 3/4] libmount: Set each optstr's to NULL if failed

Namhyung Kim
2013-09-25T15:32:32Z

When mnt_split_optstr() failed in the middle, vfs, fs, user optstr's
are freed but not reset. It can lead to double frees at the end of
mnt_fs_{ap,pre}pend_options().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
libmount/src/optstr.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 5e9e708..17b129d 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -567,12 +567,18 @@ int mnt_split_optstr(const char *optstr, char **user, char **vfs,
rc = __mnt_optstr_append_option(fs, name, namesz,
val, valsz);
if (rc) {
- if (vfs)
+ if (vfs) {
free(*vfs);
- if (fs)
+ *vfs = NULL;
+ }
+ if (fs) {
free(*fs);
- if (user)
+ *fs = NULL;
+ }
+ if (user) {
free(*user);
+ *user = NULL;
+ }
return rc;
}
}
--
1.7.9.2