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:
Michael Matz 2019-12-14 23:58:45 +01:00
parent 65f74a4df0
commit 2fb79a6326
2 changed files with 9 additions and 3 deletions

View file

@ -749,7 +749,9 @@ LIBTCCAPI TCCState *tcc_new(void)
s = tcc_mallocz(sizeof(TCCState));
if (!s)
return NULL;
WAIT_SEM();
++nb_states;
POST_SEM();
#undef gnu_ext
@ -958,8 +960,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
#endif
tcc_free(s1);
WAIT_SEM();
if (0 == --nb_states)
tcc_memcheck();
POST_SEM();
}
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)

View file

@ -105,13 +105,15 @@ void parse_args(TCCState *s)
else if (a[1] == 'L')
tcc_add_library_path(s, a+2);
else if (a[1] == 'D') {
char *eq = strchr(a+2, '=');
char *dup = strdup(a);
char *eq = strchr(dup+2, '=');
if (eq) {
*eq = 0;
tcc_define_symbol(s, a+2, eq+1);
tcc_define_symbol(s, dup+2, eq+1);
*eq = '=';
} else
tcc_define_symbol(s, a+2, NULL);
tcc_define_symbol(s, dup+2, NULL);
free(dup);
}
}
}