diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-05 06:35:02 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-05 06:35:02 +0000 |
commit | 01cfae3beb0b649ca2ae879825349cf0330a3549 (patch) | |
tree | f7556d2c60e217dffe751979cb2edffb78d69cfe /vm.c | |
parent | 90645fd4371abcb63d4fdce7ed75d14fb265125e (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 'vm.c')
-rw-r--r-- | vm.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -90,6 +90,8 @@ VM_CFP_IN_HEAP_P(const rb_thread_t *th, const rb_control_frame_t *cfp) { const VALUE *start = th->stack; const VALUE *end = (VALUE *)th->stack + th->stack_size; + VM_ASSERT(start != NULL); + if (start <= (VALUE *)cfp && (VALUE *)cfp < end) { return FALSE; } @@ -103,6 +105,8 @@ VM_EP_IN_HEAP_P(const rb_thread_t *th, const VALUE *ep) { const VALUE *start = th->stack; const VALUE *end = (VALUE *)th->cfp; + VM_ASSERT(start != NULL); + if (start <= ep && ep < end) { return FALSE; } @@ -2315,7 +2319,7 @@ static int thread_recycle_stack_count = 0; static VALUE * thread_recycle_stack(size_t size) { - if (thread_recycle_stack_count) { + if (thread_recycle_stack_count > 0) { /* TODO: check stack size if stack sizes are variable */ return thread_recycle_stack_slot[--thread_recycle_stack_count]; } @@ -2331,6 +2335,8 @@ thread_recycle_stack(size_t size) void rb_thread_recycle_stack_release(VALUE *stack) { + VM_ASSERT(stack != NULL); + #if USE_THREAD_DATA_RECYCLE if (thread_recycle_stack_count < RECYCLE_MAX) { thread_recycle_stack_slot[thread_recycle_stack_count++] = stack; @@ -2414,6 +2420,10 @@ thread_free(void *ptr) if (ptr) { th = ptr; + if (th->stack != NULL) { + rb_thread_recycle_stack_release(th->stack); + th->stack = NULL; + } if (!th->root_fiber) { RUBY_FREE_UNLESS_NULL(th->stack); |