Skip to content

Commit 3a89d8f

Browse files
committed
php#19: Memory leaks fixed for GC and coroutine tests.
1 parent c768c1f commit 3a89d8f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Zend/zend_fibers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,14 @@ ZEND_API void zend_fiber_destroy_context(zend_fiber_context *context)
461461
{
462462
zend_observer_fiber_destroy_notify(context);
463463

464+
// This code allows freeing the memory of the context independently of the stack memory.
465+
zend_fiber_stack *stack = context->stack;
466+
464467
if (context->cleanup) {
465468
context->cleanup(context);
466469
}
467470

468-
zend_fiber_stack_free(context->stack);
471+
zend_fiber_stack_free(stack);
469472
}
470473

471474
ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)

Zend/zend_gc.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,10 @@ ZEND_API int zend_gc_collect_cycles(void)
22382238
zend_refcounted *p;
22392239
uint32_t gc_flags = 0;
22402240
uint32_t idx, end;
2241-
#ifndef PHP_ASYNC_API
2241+
#ifdef PHP_ASYNC_API
2242+
stack->next = NULL;
2243+
stack->prev = NULL;
2244+
#else
22422245
int count;
22432246
gc_stack stack;
22442247
stack.prev = NULL;
@@ -2351,7 +2354,7 @@ ZEND_API int zend_gc_collect_cycles(void)
23512354
}
23522355
}
23532356

2354-
GC_COLLECT_FREE_STACK;
2357+
gc_stack_free(GC_COLLECT_STACK);
23552358

23562359
#ifdef PHP_ASYNC_API
23572360
end = GC_G(first_unused);

0 commit comments

Comments
 (0)