# HG changeset patch
# User David A. Holland
# Date 1373391340 14400
# Node ID eaae8014a94aede976c0bb34645de6f2c7bb9e0e
# Parent  b17209c1ced56914bdbd285cd44f08f8e0b4094b
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.

diff -r b17209c1ced5 -r eaae8014a94a CHANGES
--- 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
diff -r b17209c1ced5 -r eaae8014a94a main.c
--- 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);
 }