History

tccgen.c: Fix memory leak involving asm_label.

Edmund Grimley Evans committed 11 years ago

Commit 8eab5561 parent 9bf0e571 file · +9 −5Browse files

Unified · Split

tccgen.c+9−5
@@ -454,7 +454,7 @@ static Sym *external_sym(int v, CType *type, int r, char *asm_label) · 453 unmodified lines
454454 if (!s) {
455455 /* push forward reference */
456456 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
457− s->asm_label = asm_label;
457+ s->asm_label = asm_label ? tcc_strdup(asm_label) : 0;
458458 s->type.t |= VT_EXTERN;
459459 } else if (s->type.ref == func_old_type.ref) {
460460 s->type.ref = type->ref;
@@ -5908,7 +5908,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 5447 unmodified lines
59085908 if (v) {
59095909 if (scope != VT_CONST || !sym) {
59105910 sym = sym_push(v, type, r | VT_SYM, 0);
5911− sym->asm_label = asm_label;
5911+ sym->asm_label = asm_label ? tcc_strdup(asm_label) : 0;
59125912 }
59135913 /* update symbol definition */
59145914 if (sec) {
@@ -6139,6 +6139,7 @@ static int decl0(int l, int is_for_loop_init) · 224 unmodified lines
61396139 CType type, btype;
61406140 Sym *sym;
61416141 AttributeDef ad;
6142+ char *asm_label = 0; // associated asm label
61426143
61436144 while (1) {
61446145 if (!parse_btype(&btype, &ad)) {
@@ -6174,7 +6175,6 @@ static int decl0(int l, int is_for_loop_init) · 29 unmodified lines
61746175 continue;
61756176 }
61766177 while (1) { /* iterate thru each declaration */
6177− char *asm_label; // associated asm label
61786178 type = btype;
61796179 type_decl(&type, &ad, &v, TYPE_DIRECT);
61806180 #if 0
@@ -6195,7 +6195,8 @@ static int decl0(int l, int is_for_loop_init) · 14 unmodified lines
61956195 func_decl_list(sym);
61966196 }
61976197
6198− asm_label = NULL;
6198+ tcc_free(asm_label);
6199+ asm_label = 0;
61996200 if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
62006201 CString astr;
62016202
@@ -6373,8 +6374,10 @@ static int decl0(int l, int is_for_loop_init) · 171 unmodified lines
63736374 }
63746375 }
63756376 if (tok != ',') {
6376− if (is_for_loop_init)
6377+ if (is_for_loop_init) {
6378+ tcc_free(asm_label);
63776379 return 1;
6380+ }
63786381 skip(';');
63796382 break;
63806383 }
@@ -6383,6 +6386,7 @@ static int decl0(int l, int is_for_loop_init) · 2 unmodified lines
63836386 ad.a.aligned = 0;
63846387 }
63856388 }
6389+ tcc_free(asm_label);
63866390 return 0;
63876391 }
63886392

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t