Fix some races
protect some more accesses to global data with the semaphore. (And for the testcase: don't just write into global data, use local copies; it's not important for speed here).
This commit is contained in:
parent
65f74a4df0
commit
2fb79a6326
2 changed files with 9 additions and 3 deletions
4
libtcc.c
4
libtcc.c
|
@ -749,7 +749,9 @@ LIBTCCAPI TCCState *tcc_new(void)
|
||||||
s = tcc_mallocz(sizeof(TCCState));
|
s = tcc_mallocz(sizeof(TCCState));
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
WAIT_SEM();
|
||||||
++nb_states;
|
++nb_states;
|
||||||
|
POST_SEM();
|
||||||
|
|
||||||
#undef gnu_ext
|
#undef gnu_ext
|
||||||
|
|
||||||
|
@ -958,8 +960,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tcc_free(s1);
|
tcc_free(s1);
|
||||||
|
WAIT_SEM();
|
||||||
if (0 == --nb_states)
|
if (0 == --nb_states)
|
||||||
tcc_memcheck();
|
tcc_memcheck();
|
||||||
|
POST_SEM();
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
||||||
|
|
|
@ -105,13 +105,15 @@ void parse_args(TCCState *s)
|
||||||
else if (a[1] == 'L')
|
else if (a[1] == 'L')
|
||||||
tcc_add_library_path(s, a+2);
|
tcc_add_library_path(s, a+2);
|
||||||
else if (a[1] == 'D') {
|
else if (a[1] == 'D') {
|
||||||
char *eq = strchr(a+2, '=');
|
char *dup = strdup(a);
|
||||||
|
char *eq = strchr(dup+2, '=');
|
||||||
if (eq) {
|
if (eq) {
|
||||||
*eq = 0;
|
*eq = 0;
|
||||||
tcc_define_symbol(s, a+2, eq+1);
|
tcc_define_symbol(s, dup+2, eq+1);
|
||||||
*eq = '=';
|
*eq = '=';
|
||||||
} else
|
} else
|
||||||
tcc_define_symbol(s, a+2, NULL);
|
tcc_define_symbol(s, dup+2, NULL);
|
||||||
|
free(dup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue