History

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).

Michael Matz committed 6 years ago

Commit 2fb79a61 parent 65f74a42 files · +9 −3Browse files

Unified · Split

2 files
  1. libtcc.c +4 −0
  2. tests/libtcc_test_mt.c +5 −3
libtcc.c+4−0
@@ -749,7 +749,9 @@ LIBTCCAPI TCCState *tcc_new(void) · 748 unmodified lines
749749 s = tcc_mallocz(sizeof(TCCState));
750750 if (!s)
751751 return NULL;
752+ WAIT_SEM();
752753 ++nb_states;
754+ POST_SEM();
753755
754756 #undef gnu_ext
755757
@@ -958,8 +960,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 202 unmodified lines
958960 #endif
959961
960962 tcc_free(s1);
963+ WAIT_SEM();
961964 if (0 == --nb_states)
962965 tcc_memcheck();
966+ POST_SEM();
963967 }
964968
965969 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
tests/libtcc_test_mt.c+5−3
@@ -105,13 +105,15 @@ void parse_args(TCCState *s) · 104 unmodified lines
105105 else if (a[1] == 'L')
106106 tcc_add_library_path(s, a+2);
107107 else if (a[1] == 'D') {
108− char *eq = strchr(a+2, '=');
108+ char *dup = strdup(a);
109+ char *eq = strchr(dup+2, '=');
109110 if (eq) {
110111 *eq = 0;
111− tcc_define_symbol(s, a+2, eq+1);
112+ tcc_define_symbol(s, dup+2, eq+1);
112113 *eq = '=';
113114 } else
114− tcc_define_symbol(s, a+2, NULL);
115+ tcc_define_symbol(s, dup+2, NULL);
116+ free(dup);
115117 }
116118 }
117119 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t