@@ -689,6 +689,11 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
689689 closure -> func .common .fn_flags |= ZEND_ACC_CLOSURE ;
690690 closure -> func .common .fn_flags &= ~ZEND_ACC_IMMUTABLE ;
691691
692+ zend_string_addref (closure -> func .op_array .function_name );
693+ if (closure -> func .op_array .refcount ) {
694+ (* closure -> func .op_array .refcount )++ ;
695+ }
696+
692697 /* For fake closures, we want to reuse the static variables of the original function. */
693698 if (!is_fake ) {
694699 if (closure -> func .op_array .static_variables ) {
@@ -722,24 +727,20 @@ static void zend_create_closure_ex(zval *res, zend_function *func, zend_class_en
722727 if (func -> common .scope != scope ) {
723728 func -> common .scope = scope ;
724729 }
725- closure -> func .op_array .fn_flags &= ~ZEND_ACC_HEAP_RT_CACHE ;
726730 ptr = zend_arena_alloc (& CG (arena ), func -> op_array .cache_size );
727731 ZEND_MAP_PTR_SET (func -> op_array .run_time_cache , ptr );
728732 ZEND_MAP_PTR_SET (closure -> func .op_array .run_time_cache , ptr );
733+ closure -> func .op_array .fn_flags &= ~ZEND_ACC_HEAP_RT_CACHE ;
729734 } else {
730735 /* Otherwise, we use a non-shared runtime cache */
731- closure -> func .op_array .fn_flags |= ZEND_ACC_HEAP_RT_CACHE ;
732736 ptr = emalloc (sizeof (void * ) + func -> op_array .cache_size );
733737 ZEND_MAP_PTR_INIT (closure -> func .op_array .run_time_cache , ptr );
734738 ptr = (char * )ptr + sizeof (void * );
735739 ZEND_MAP_PTR_SET (closure -> func .op_array .run_time_cache , ptr );
740+ closure -> func .op_array .fn_flags |= ZEND_ACC_HEAP_RT_CACHE ;
736741 }
737742 memset (ptr , 0 , func -> op_array .cache_size );
738743 }
739- zend_string_addref (closure -> func .op_array .function_name );
740- if (closure -> func .op_array .refcount ) {
741- (* closure -> func .op_array .refcount )++ ;
742- }
743744 } else {
744745 memcpy (& closure -> func , func , sizeof (zend_internal_function ));
745746 closure -> func .common .fn_flags |= ZEND_ACC_CLOSURE ;
0 commit comments