changeset 135:eaae8014a94a

Don't assert and leak memory if failing during argument collection. Once you have a -D option or a -include foo option, you need to clean up the arrays those are accumulated in if you die before they're collected and handled.
author David A. Holland
date Tue, 09 Jul 2013 13:35:40 -0400
parents b17209c1ced5
children 59680a727e9d
files CHANGES main.c
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Sun Jun 16 22:41:27 2013 -0400
+++ b/CHANGES	Tue Jul 09 13:35:40 2013 -0400
@@ -1,3 +1,7 @@
+pending
+   - Don't leak memory and assert if a bad command-line option comes
+     after a -D or a -include foo.
+
 release 0.3 (20130616)
    - Don't eval the control expression of the first #if of a block when
      already in a false block; it might not be valid. Reported by
--- a/main.c	Sun Jun 16 22:41:27 2013 -0400
+++ b/main.c	Tue Jul 09 13:35:40 2013 -0400
@@ -108,6 +108,16 @@
 void
 commandline_macros_cleanup(void)
 {
+	unsigned i, num;
+	struct commandline_macro *cm;
+
+	num = array_num(&commandline_macros);
+	for (i=0; i<num; i++) {
+		cm = array_get(&commandline_macros, i);
+		dofree(cm, sizeof(*cm));
+	}
+	array_setsize(&commandline_macros, 0);
+	
 	array_cleanup(&commandline_macros);
 }
 
@@ -252,6 +262,16 @@
 void
 commandline_files_cleanup(void)
 {
+	unsigned i, num;
+	struct commandline_file *cf;
+
+	num = array_num(&commandline_files);
+	for (i=0; i<num; i++) {
+		cf = array_get(&commandline_files, i);
+		dofree(cf, sizeof(*cf));
+	}
+	array_setsize(&commandline_files, 0);
+
 	array_cleanup(&commandline_files);
 }