Skip to content

Commit 04f64a6

Browse files
author
Edmond
committed
Fix memory leak in zend_fcall_t cleanup in zend_fibers.c
Added proper cleanup of fcall parameters and named_params in two locations: - coroutine_entry_point: free params array and decrement named_params refcount - zend_fiber_object_destroy: same cleanup when fcall ownership wasn't taken This matches the correct cleanup pattern used in ext/async/coroutine.c and prevents memory leaks when fiber is destroyed.
1 parent f4d5d11 commit 04f64a6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Zend/zend_fibers.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,18 @@ static void coroutine_entry_point(void)
11201120
fiber->fcall = NULL;
11211121
}
11221122

1123+
if (fcall->fci.param_count) {
1124+
for (uint32_t i = 0; i < fcall->fci.param_count; i++) {
1125+
zval_ptr_dtor(&fcall->fci.params[i]);
1126+
}
1127+
efree(fcall->fci.params);
1128+
}
1129+
1130+
if (fcall->fci.named_params) {
1131+
GC_DELREF(fcall->fci.named_params);
1132+
fcall->fci.named_params = NULL;
1133+
}
1134+
11231135
zval_ptr_dtor(&fcall->fci.function_name);
11241136
ZVAL_UNDEF(&fcall->fci.function_name);
11251137
efree(fcall);
@@ -1279,6 +1291,19 @@ static void zend_fiber_object_destroy(zend_object *object)
12791291
if (fiber->fcall != NULL) {
12801292
zend_fcall_t *fcall = fiber->fcall;
12811293
fiber->fcall = NULL;
1294+
1295+
if (fcall->fci.param_count) {
1296+
for (uint32_t i = 0; i < fcall->fci.param_count; i++) {
1297+
zval_ptr_dtor(&fcall->fci.params[i]);
1298+
}
1299+
efree(fcall->fci.params);
1300+
}
1301+
1302+
if (fcall->fci.named_params) {
1303+
GC_DELREF(fcall->fci.named_params);
1304+
fcall->fci.named_params = NULL;
1305+
}
1306+
12821307
zval_ptr_dtor(&fcall->fci.function_name);
12831308
efree(fcall);
12841309
}

0 commit comments

Comments
 (0)