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_INLN void tok_str_new(TokenString *s);
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_tok(TokenString *s);
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 */
for (i = 0; i < s->nb_inline_fns; ++i) {
struct InlineFunc *fn = s->inline_fns[i];
if (fn->sym) {
tok_str_free(fn->func_str->str);
tal_free(tokstr_alloc, fn->func_str);
}
if (fn->sym)
tok_str_free(fn->func_str);
}
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;
}
ST_FUNC void tok_str_free(int *str)
ST_FUNC void tok_str_free_str(int *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)
{
int *str, size;
@ -1123,8 +1129,7 @@ ST_FUNC void end_macro(void)
if (str->alloc == 2) {
str->alloc = 3; /* just mark as finished */
} else {
tok_str_free(str->str);
tal_free(tokstr_alloc, str);
tok_str_free(str);
}
}
@ -1328,7 +1333,7 @@ ST_FUNC void free_defines(Sym *b)
while (define_stack != b) {
Sym *top = define_stack;
define_stack = top->prev;
tok_str_free(top->d);
tok_str_free_str(top->d);
define_undef(top);
sym_free(top);
}
@ -3138,10 +3143,10 @@ static int macro_subst_tok(
for (i = 0; i < ws_str.len; 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;
} else {
tok_str_free(ws_str.str);
tok_str_free_str(ws_str.str);
}
next_nomacro(); /* eat '(' */
@ -3208,7 +3213,7 @@ static int macro_subst_tok(
sa = args;
while (sa) {
sa1 = sa->prev;
tok_str_free(sa->d);
tok_str_free_str(sa->d);
sym_free(sa);
sa = sa1;
}
@ -3223,7 +3228,7 @@ static int macro_subst_tok(
*nested_list = sa1->prev;
sym_free(sa1);
if (mstr != s->d)
tok_str_free(mstr);
tok_str_free_str(mstr);
}
return 0;
}
@ -3400,7 +3405,7 @@ no_subst:
}
}
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 */
cstr_free(&tokcstr);
cstr_free(&cstr_buf);
tok_str_free(tokstr_buf.str);
tok_str_free_str(tokstr_buf.str);
/* free allocators */
tal_delete(toksym_alloc);