Skip to content

Commit ca1b731

Browse files
nielsdossaundefined
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 31f388c commit ca1b731

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
@@ -4737,7 +4737,7 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
47374737
#ifdef ZTS
47384738
static void zend_jit_globals_dtor(zend_jit_globals *jit_globals)
47394739
{
4740-
zend_jit_trace_free_caches();
4740+
zend_jit_trace_free_caches(jit_globals);
47414741
}
47424742
#endif
47434743

@@ -5064,7 +5064,7 @@ ZEND_EXT_API void zend_jit_shutdown(void)
50645064
#ifdef ZTS
50655065
ts_free_id(jit_globals_id);
50665066
#else
5067-
zend_jit_trace_free_caches();
5067+
zend_jit_trace_free_caches(&jit_globals);
50685068
#endif
50695069
}
50705070

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8385,10 +8385,10 @@ static void zend_jit_trace_reset_caches(void)
83858385
#endif
83868386
}
83878387

8388-
static void zend_jit_trace_free_caches(void)
8388+
static void zend_jit_trace_free_caches(zend_jit_globals *jit_globals)
83898389
{
8390-
if (JIT_G(exit_counters)) {
8391-
free(JIT_G(exit_counters));
8390+
if (jit_globals->exit_counters) {
8391+
free(jit_globals->exit_counters);
83928392
}
83938393
}
83948394

0 commit comments

Comments
 (0)