From abbe1f85bea1a6316fc06b559713b2584535b5a0 Mon Sep 17 00:00:00 2001 From: Wang Renxin Date: Tue, 7 Nov 2017 11:21:15 +0800 Subject: [PATCH] *should mark the whole outer-scope chain when collecting garbage with a closure. --- core/my_basic.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/my_basic.c b/core/my_basic.c index bc9eaf5..10b5490 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -6405,9 +6405,11 @@ static int _gc_add_reachable(void* data, void* extra, void* h) { case _DT_ROUTINE: if(obj->data.routine->type == MB_RT_LAMBDA) { if(!_ht_find(ht, &obj->data.routine->func.lambda.ref)) { + _running_context_ref_t* outs = obj->data.routine->func.lambda.outer_scope; _ht_set_or_insert(ht, &obj->data.routine->func.lambda.ref, obj->data.routine); - if(obj->data.routine->func.lambda.outer_scope) { - _HT_FOREACH(obj->data.routine->func.lambda.outer_scope->scope->var_dict, _do_nothing_on_object, _gc_add_reachable, ht); + while(outs) { + _HT_FOREACH(outs->scope->var_dict, _do_nothing_on_object, _gc_add_reachable, ht); + outs = outs->prev; } } }