Skip to content

Commit b33d472

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix possible exit_counters memory leak in ZTS build
2 parents c8ec2ed + 29efbe5 commit b33d472

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,6 +4728,13 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
47284728
zend_jit_trace_init_caches();
47294729
}
47304730

4731+
#ifdef ZTS
4732+
static void zend_jit_globals_dtor(zend_jit_globals *jit_globals)
4733+
{
4734+
zend_jit_trace_free_caches();
4735+
}
4736+
#endif
4737+
47314738
static int zend_jit_parse_config_num(zend_long jit)
47324739
{
47334740
if (jit == 0) {
@@ -4840,7 +4847,7 @@ ZEND_EXT_API int zend_jit_debug_config(zend_long old_val, zend_long new_val, int
48404847
ZEND_EXT_API void zend_jit_init(void)
48414848
{
48424849
#ifdef ZTS
4843-
jit_globals_id = ts_allocate_id(&jit_globals_id, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, NULL);
4850+
jit_globals_id = ts_allocate_id(&jit_globals_id, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, zend_jit_globals_dtor);
48444851
#else
48454852
zend_jit_globals_ctor(&jit_globals);
48464853
#endif
@@ -5048,9 +5055,9 @@ ZEND_EXT_API void zend_jit_shutdown(void)
50485055
zend_jit_perf_jitdump_close();
50495056
}
50505057
#endif
5051-
if (JIT_G(exit_counters)) {
5052-
free(JIT_G(exit_counters));
5053-
}
5058+
#ifndef ZTS
5059+
zend_jit_trace_free_caches();
5060+
#endif
50545061
}
50555062

50565063
static void zend_jit_reset_counters(void)

ext/opcache/jit/zend_jit_trace.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8396,6 +8396,13 @@ static void zend_jit_trace_reset_caches(void)
83968396
#endif
83978397
}
83988398

8399+
static void zend_jit_trace_free_caches(void)
8400+
{
8401+
if (JIT_G(exit_counters)) {
8402+
free(JIT_G(exit_counters));
8403+
}
8404+
}
8405+
83998406
static void zend_jit_trace_restart(void)
84008407
{
84018408
ZEND_JIT_TRACE_NUM = 1;

0 commit comments

Comments
 (0)