Skip to content

Commit 40a1a86

Browse files
nielsdospatrickallaert
authored andcommitted
Fix module shutdown crash during ZTS JIT shutdown
Commit a211956 fixed a leak by adding a TSRM destructor for the JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it will call all the destructors. The JIT globals destructor will be invoked, but will always access the main thread globals using JIT_G. This means that instead of freeing the JIT globals in the different threads, the one in the main thread is freed repeatedly over and over, crashing PHP. Fix it by always passing the pointer instead of relying on JIT_G. Closes GH-10835. (cherry picked from commit b3e28e2)
1 parent 18b43d2 commit 40a1a86

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,7 +4762,7 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
47624762
#ifdef ZTS
47634763
static void zend_jit_globals_dtor(zend_jit_globals *jit_globals)
47644764
{
4765-
zend_jit_trace_free_caches();
4765+
zend_jit_trace_free_caches(jit_globals);
47664766
}
47674767
#endif
47684768

@@ -5081,7 +5081,7 @@ ZEND_EXT_API void zend_jit_shutdown(void)
50815081
#ifdef ZTS
50825082
ts_free_id(jit_globals_id);
50835083
#else
5084-
zend_jit_trace_free_caches();
5084+
zend_jit_trace_free_caches(&jit_globals);
50855085
#endif
50865086
}
50875087

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8324,10 +8324,10 @@ static void zend_jit_trace_reset_caches(void)
83248324
#endif
83258325
}
83268326

8327-
static void zend_jit_trace_free_caches(void)
8327+
static void zend_jit_trace_free_caches(zend_jit_globals *jit_globals)
83288328
{
8329-
if (JIT_G(exit_counters)) {
8330-
free(JIT_G(exit_counters));
8329+
if (jit_globals->exit_counters) {
8330+
free(jit_globals->exit_counters);
83318331
}
83328332
}
83338333

0 commit comments

Comments
 (0)