diff lwasm/pass1.c @ 93:5bf9edabd661

Squashed the remaining memory leaks revealed by valgrind
author lost@l-w.ca
date Wed, 22 Jun 2011 19:28:36 -0600
parents 8fa52c3f2970
children b3557f8325f7
line wrap: on
line diff
--- a/lwasm/pass1.c	Wed Jun 22 19:13:06 2011 -0600
+++ b/lwasm/pass1.c	Wed Jun 22 19:28:36 2011 -0600
@@ -55,7 +55,7 @@
 	line_t *cl;
 	char *p1;
 	int stspace;
-	char *tok, *sym;
+	char *tok, *sym = NULL;
 	int opnum;
 	int lc = 1;
 	int nomacro;
@@ -63,6 +63,8 @@
 	for (;;)
 	{
 		nomacro = 0;
+		if (sym)
+			lw_free(sym);
 		sym = NULL;
 		line = input_readline(as);
 		if (!line)
@@ -247,6 +249,7 @@
 		if (*tok)
 		{
 			// look up operation code
+			lw_free(sym);
 			sym = lw_strndup(tok, p1 - tok);
 			for (; *p1 && isspace(*p1); p1++)
 				/* do nothing */ ;
@@ -350,8 +353,6 @@
 		}
 	
 	linedone:
-		lw_free(sym);
-		
 		if (!as -> skipcond && !as -> inmacro)
 		{
 			if (cl -> sym && cl -> symset == 0)
@@ -369,6 +370,10 @@
 		}
 		
 	nextline:
+		if (sym)
+			lw_free(sym);
+		sym = NULL;
+		
 		lw_free(line);
 		
 		// if we've hit the "end" bit, finish out