[Ocfs2-tools-devel] [PATCH 3/8] Fix a memory leak problem in mount.ocfs2.c

piaojun piaojun at huawei.com
Wed Mar 18 00:39:49 PDT 2015


In main(), the memory allocated in fix_opts_string() should be freed after
use.

Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>

---
 mount.ocfs2/mount.ocfs2.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/mount.ocfs2/mount.ocfs2.c b/mount.ocfs2/mount.ocfs2.c
index a1c8698..2c23ce1 100644
--- a/mount.ocfs2/mount.ocfs2.c
+++ b/mount.ocfs2/mount.ocfs2.c
@@ -313,7 +313,7 @@ int main(int argc, char **argv)
 	int group_join = 0;
 	struct stat statbuf;
 	const char *spec;
-
+	char *opts_string = NULL;
 	initialize_ocfs_error_table();
 	initialize_o2dl_error_table();
 	initialize_o2cb_error_table();
@@ -452,12 +452,9 @@ int main(int argc, char **argv)
 	}

 	change_local_hb_io_priority(fs, mo.dev);
-
-	update_mtab_entry(mo.dev, mo.dir, OCFS2_FS_NAME,
-			  fix_opts_string(((mo.flags & ~MS_NOMTAB) |
-					   (clustered ? MS_NETDEV : 0)),
-					  mo.xtra_opts, NULL),
-			  mo.flags, 0, 0);
+	opts_string = fix_opts_string(((mo.flags & ~MS_NOMTAB) |
+				(clustered ? MS_NETDEV : 0)), mo.xtra_opts, NULL);
+	update_mtab_entry(mo.dev, mo.dir, OCFS2_FS_NAME, opts_string, mo.flags, 0, 0);

 	block_signals (SIG_UNBLOCK);

@@ -474,6 +471,7 @@ bail:
 		free(mo.xtra_opts);
 	if (mo.type)
 		free(mo.type);
-
+	if (opts_string)
+		free(opts_string);
 	return ret ? 1 : 0;
 }
-- 1.8.4.3




More information about the Ocfs2-tools-devel mailing list