diff --git a/libtcc.c b/libtcc.c index 3094d2df..e1bfe028 100644 --- a/libtcc.c +++ b/libtcc.c @@ -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) diff --git a/tests/libtcc_test_mt.c b/tests/libtcc_test_mt.c index 266870fe..03b9f799 100644 --- a/tests/libtcc_test_mt.c +++ b/tests/libtcc_test_mt.c @@ -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); } } }