Skip to content

Commit 29efbe5

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

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
@@ -4734,6 +4734,13 @@ static void zend_jit_globals_ctor(zend_jit_globals *jit_globals)
47344734
zend_jit_trace_init_caches();
47354735
}
47364736

4737+
#ifdef ZTS
4738+
static void zend_jit_globals_dtor(zend_jit_globals *jit_globals)
4739+
{
4740+
zend_jit_trace_free_caches();
4741+
}
4742+
#endif
4743+
47374744
static int zend_jit_parse_config_num(zend_long jit)
47384745
{
47394746
if (jit == 0) {
@@ -4846,7 +4853,7 @@ ZEND_EXT_API int zend_jit_debug_config(zend_long old_val, zend_long new_val, int
48464853
ZEND_EXT_API void zend_jit_init(void)
48474854
{
48484855
#ifdef ZTS
4849-
jit_globals_id = ts_allocate_id(&jit_globals_id, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, NULL);
4856+
jit_globals_id = ts_allocate_id(&jit_globals_id, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, zend_jit_globals_dtor);
48504857
#else
48514858
zend_jit_globals_ctor(&jit_globals);
48524859
#endif
@@ -5054,9 +5061,9 @@ ZEND_EXT_API void zend_jit_shutdown(void)
50545061
zend_jit_perf_jitdump_close();
50555062
}
50565063
#endif
5057-
if (JIT_G(exit_counters)) {
5058-
free(JIT_G(exit_counters));
5059-
}
5064+
#ifndef ZTS
5065+
zend_jit_trace_free_caches();
5066+
#endif
50605067
}
50615068

50625069
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
@@ -8385,6 +8385,13 @@ static void zend_jit_trace_reset_caches(void)
83858385
#endif
83868386
}
83878387

8388+
static void zend_jit_trace_free_caches(void)
8389+
{
8390+
if (JIT_G(exit_counters)) {
8391+
free(JIT_G(exit_counters));
8392+
}
8393+
}
8394+
83888395
static void zend_jit_trace_restart(void)
83898396
{
83908397
ZEND_JIT_TRACE_NUM = 1;

0 commit comments

Comments
 (0)