comparison 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
comparison
equal deleted inserted replaced
92:19ca3108a223 93:5bf9edabd661
53 { 53 {
54 char *line; 54 char *line;
55 line_t *cl; 55 line_t *cl;
56 char *p1; 56 char *p1;
57 int stspace; 57 int stspace;
58 char *tok, *sym; 58 char *tok, *sym = NULL;
59 int opnum; 59 int opnum;
60 int lc = 1; 60 int lc = 1;
61 int nomacro; 61 int nomacro;
62 62
63 for (;;) 63 for (;;)
64 { 64 {
65 nomacro = 0; 65 nomacro = 0;
66 if (sym)
67 lw_free(sym);
66 sym = NULL; 68 sym = NULL;
67 line = input_readline(as); 69 line = input_readline(as);
68 if (!line) 70 if (!line)
69 break; 71 break;
70 if (line[0] == 1 && line[1] == 1) 72 if (line[0] == 1 && line[1] == 1)
245 tok += 2; 247 tok += 2;
246 } 248 }
247 if (*tok) 249 if (*tok)
248 { 250 {
249 // look up operation code 251 // look up operation code
252 lw_free(sym);
250 sym = lw_strndup(tok, p1 - tok); 253 sym = lw_strndup(tok, p1 - tok);
251 for (; *p1 && isspace(*p1); p1++) 254 for (; *p1 && isspace(*p1); p1++)
252 /* do nothing */ ; 255 /* do nothing */ ;
253 256
254 for (opnum = 0; instab[opnum].opcode; opnum++) 257 for (opnum = 0; instab[opnum].opcode; opnum++)
348 } 351 }
349 } 352 }
350 } 353 }
351 354
352 linedone: 355 linedone:
353 lw_free(sym);
354
355 if (!as -> skipcond && !as -> inmacro) 356 if (!as -> skipcond && !as -> inmacro)
356 { 357 {
357 if (cl -> sym && cl -> symset == 0) 358 if (cl -> sym && cl -> symset == 0)
358 { 359 {
359 debug_message(as, 50, "Register symbol %s: %s", cl -> sym, lw_expr_print(cl -> addr)); 360 debug_message(as, 50, "Register symbol %s: %s", cl -> sym, lw_expr_print(cl -> addr));
367 } 368 }
368 debug_message(as, 40, "Line address: %s", lw_expr_print(cl -> addr)); 369 debug_message(as, 40, "Line address: %s", lw_expr_print(cl -> addr));
369 } 370 }
370 371
371 nextline: 372 nextline:
373 if (sym)
374 lw_free(sym);
375 sym = NULL;
376
372 lw_free(line); 377 lw_free(line);
373 378
374 // if we've hit the "end" bit, finish out 379 // if we've hit the "end" bit, finish out
375 if (as -> endseen) 380 if (as -> endseen)
376 return; 381 return;