summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-05 06:35:02 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-05 06:35:02 +0000
commit01cfae3beb0b649ca2ae879825349cf0330a3549 (patch)
treef7556d2c60e217dffe751979cb2edffb78d69cfe /cont.c
parent90645fd4371abcb63d4fdce7ed75d14fb265125e (diff)
merge revision(s) 59462,59474: [Backport #13772]
release VM stack properly. * cont.c: r55766 change the handling method of Fiber's VM stack. Resumed Fiber points NULL as VM stack and running Thread has responsibility to manage it (marking and releasing). However, thread_start_func_2()@thread.c and thread_free()@vm.c doesn't free the VM stack if corresponding root Fiber is exist. This causes memory leak. [Bug #13772] * cont.c (root_fiber_alloc): fib->cont.saved_thread.ec.stack should be NULL because running thread has responsibility to manage this stack. * vm.c (rb_thread_recycle_stack_release): assert given stack is not NULL (callers should care it). fix stack storing for root fibers. * cont.c (root_fiber_alloc): this function is called by fiber_current() and fiber_store(). fiber_current() should clear VM stack information in a fiber data because runnning thread knows stack information and has responsibility to manage it. However fiber_store() requires to remain VM stack information in a fiber data because the responsibility to manage VM stack is moved to the Fiber from the Thread (and switch to another fiber). * cont.c (root_fiber_alloc): save thread's fiber and root_fiber information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/cont.c b/cont.c
index ab4f2bc830..c56ea0f6e6 100644
--- a/cont.c
+++ b/cont.c
@@ -575,6 +575,8 @@ cont_restore_thread(rb_context_t *cont)
th->root_lep = sth->root_lep;
th->root_svar = sth->root_svar;
th->ensure_list = sth->ensure_list;
+ VM_ASSERT(th->stack != NULL);
+ VM_ASSERT(sth->status == THREAD_RUNNABLE);
}
#if FIBER_USE_NATIVE
@@ -1316,6 +1318,7 @@ root_fiber_alloc(rb_thread_t *th)
#endif
fib->status = RUNNING;
+ th->root_fiber = th->fiber = fib;
return fib;
}
@@ -1324,9 +1327,9 @@ fiber_current(void)
{
rb_thread_t *th = GET_THREAD();
if (th->fiber == 0) {
- /* save root */
rb_fiber_t *fib = root_fiber_alloc(th);
- th->root_fiber = th->fiber = fib;
+ /* Running thread object has stack management responsibility */
+ fib->cont.saved_thread.stack = NULL;
}
return th->fiber;
}
@@ -1367,9 +1370,8 @@ fiber_store(rb_fiber_t *next_fib, rb_thread_t *th)
cont_save_thread(&fib->cont, th);
}
else {
- /* create current fiber */
+ /* create root fiber */
fib = root_fiber_alloc(th);
- th->root_fiber = th->fiber = fib;
}
#if FIBER_USE_NATIVE