tccgen: fix inline_functions double free fix

master
grischka 2016-11-11 20:25:13 +01:00
parent 7c28c9b13f
commit 59216d3db0
3 changed files with 19 additions and 15 deletions

3
tcc.h
View File

@ -1171,7 +1171,8 @@ ST_FUNC void save_parse_state(ParseState *s);
ST_FUNC void restore_parse_state(ParseState *s); ST_FUNC void restore_parse_state(ParseState *s);
ST_INLN void tok_str_new(TokenString *s); ST_INLN void tok_str_new(TokenString *s);
ST_FUNC TokenString *tok_str_alloc(void); ST_FUNC TokenString *tok_str_alloc(void);
ST_FUNC void tok_str_free(int *str); ST_FUNC void tok_str_free(TokenString *s);
ST_FUNC void tok_str_free_str(int *str);
ST_FUNC void tok_str_add(TokenString *s, int t); ST_FUNC void tok_str_add(TokenString *s, int t);
ST_FUNC void tok_str_add_tok(TokenString *s); ST_FUNC void tok_str_add_tok(TokenString *s);
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg); ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);

View File

@ -6544,10 +6544,8 @@ ST_FUNC void free_inline_functions(TCCState *s)
/* free tokens of unused inline functions */ /* free tokens of unused inline functions */
for (i = 0; i < s->nb_inline_fns; ++i) { for (i = 0; i < s->nb_inline_fns; ++i) {
struct InlineFunc *fn = s->inline_fns[i]; struct InlineFunc *fn = s->inline_fns[i];
if (fn->sym) { if (fn->sym)
tok_str_free(fn->func_str->str); tok_str_free(fn->func_str);
tal_free(tokstr_alloc, fn->func_str);
}
} }
dynarray_reset(&s->inline_fns, &s->nb_inline_fns); dynarray_reset(&s->inline_fns, &s->nb_inline_fns);
} }

25
tccpp.c
View File

@ -1072,11 +1072,17 @@ ST_FUNC int *tok_str_dup(TokenString *s)
return str; return str;
} }
ST_FUNC void tok_str_free(int *str) ST_FUNC void tok_str_free_str(int *str)
{ {
tal_free(tokstr_alloc, str); tal_free(tokstr_alloc, str);
} }
ST_FUNC void tok_str_free(TokenString *str)
{
tok_str_free_str(str->str);
tal_free(tokstr_alloc, str);
}
ST_FUNC int *tok_str_realloc(TokenString *s, int new_size) ST_FUNC int *tok_str_realloc(TokenString *s, int new_size)
{ {
int *str, size; int *str, size;
@ -1123,8 +1129,7 @@ ST_FUNC void end_macro(void)
if (str->alloc == 2) { if (str->alloc == 2) {
str->alloc = 3; /* just mark as finished */ str->alloc = 3; /* just mark as finished */
} else { } else {
tok_str_free(str->str); tok_str_free(str);
tal_free(tokstr_alloc, str);
} }
} }
@ -1328,7 +1333,7 @@ ST_FUNC void free_defines(Sym *b)
while (define_stack != b) { while (define_stack != b) {
Sym *top = define_stack; Sym *top = define_stack;
define_stack = top->prev; define_stack = top->prev;
tok_str_free(top->d); tok_str_free_str(top->d);
define_undef(top); define_undef(top);
sym_free(top); sym_free(top);
} }
@ -3138,10 +3143,10 @@ static int macro_subst_tok(
for (i = 0; i < ws_str.len; i++) for (i = 0; i < ws_str.len; i++)
tok_str_add(tok_str, ws_str.str[i]); tok_str_add(tok_str, ws_str.str[i]);
} }
tok_str_free(ws_str.str); tok_str_free_str(ws_str.str);
return 0; return 0;
} else { } else {
tok_str_free(ws_str.str); tok_str_free_str(ws_str.str);
} }
next_nomacro(); /* eat '(' */ next_nomacro(); /* eat '(' */
@ -3208,7 +3213,7 @@ static int macro_subst_tok(
sa = args; sa = args;
while (sa) { while (sa) {
sa1 = sa->prev; sa1 = sa->prev;
tok_str_free(sa->d); tok_str_free_str(sa->d);
sym_free(sa); sym_free(sa);
sa = sa1; sa = sa1;
} }
@ -3223,7 +3228,7 @@ static int macro_subst_tok(
*nested_list = sa1->prev; *nested_list = sa1->prev;
sym_free(sa1); sym_free(sa1);
if (mstr != s->d) if (mstr != s->d)
tok_str_free(mstr); tok_str_free_str(mstr);
} }
return 0; return 0;
} }
@ -3400,7 +3405,7 @@ no_subst:
} }
} }
if (macro_str1) if (macro_str1)
tok_str_free(macro_str1); tok_str_free_str(macro_str1);
} }
@ -3542,7 +3547,7 @@ ST_FUNC void tccpp_delete(TCCState *s)
/* free static buffers */ /* free static buffers */
cstr_free(&tokcstr); cstr_free(&tokcstr);
cstr_free(&cstr_buf); cstr_free(&cstr_buf);
tok_str_free(tokstr_buf.str); tok_str_free_str(tokstr_buf.str);
/* free allocators */ /* free allocators */
tal_delete(toksym_alloc); tal_delete(toksym_alloc);