diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-02 00:50:42 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-02 00:50:42 +0000 |
commit | 657dffe0e736c08941c8c6a8a6290240637ee3fe (patch) | |
tree | 9c4b43d074f0ac3382e78c67628acbfd345ffd40 /vm.c | |
parent | c503093b129028cce7dc7097b9cac2e9e186c171 (diff) | |
download | ruby-657dffe0e736c08941c8c6a8a6290240637ee3fe.tar.gz |
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).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -2330,7 +2330,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]; } @@ -2346,6 +2346,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; @@ -2429,8 +2431,9 @@ thread_free(void *ptr) rb_thread_t *th = ptr; RUBY_FREE_ENTER("thread"); - if (!th->root_fiber) { - RUBY_FREE_UNLESS_NULL(th->ec.stack); + if (th->ec.stack != NULL) { + rb_thread_recycle_stack_release(th->ec.stack); + th->ec.stack = NULL; } if (th->locking_mutex != Qfalse) { |