summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-26 14:21:31 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-26 14:21:31 (GMT)
commit8afee516beddd2042585d69dc7a1ae4b02460902 (patch)
tree4ec47502a7fbb15ac5ed9ac8445d7eb7fbbda03d /cont.c
parent4552f747159ad3ead5827bd17c006784163a38f2 (diff)
fix freeing `th->ec` bugs.
* vm.c (thread_free): simply call rb_threadptr_root_fiber_release(). * cont.c (rb_threadptr_root_fiber_release): release th->ec (ec->fiber) iff root_fiber is NULL. If root_fiber is available, then ignore it and root fiber object will free th->ec too. * cont.c (rb_threadptr_root_fiber_setup): do not set th->root_fiber. th->root_fiber will be set if a root fiber object is created. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/cont.c b/cont.c
index a16f8b3..d0f9f27 100644
--- a/cont.c
+++ b/cont.c
@@ -440,6 +440,7 @@ fiber_free(void *ptr)
{
rb_fiber_t *fib = ptr;
RUBY_FREE_ENTER("fiber");
+
if (fib->cont.saved_ec.local_storage) {
st_free_table(fib->cont.saved_ec.local_storage);
}
@@ -1476,7 +1477,6 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th)
fib->cont.thread_ptr = th;
fiber_status_set(fib, FIBER_RESUMED); /* skip CREATED */
th->ec = &fib->cont.saved_ec;
- th->root_fiber = th->ec->fiber = fib;
#if FIBER_USE_NATIVE
#ifdef _WIN32
if (fib->fib_handle == 0) {
@@ -1486,6 +1486,24 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th)
#endif
}
+void
+rb_threadptr_root_fiber_release(rb_thread_t *th)
+{
+ if (th->root_fiber) {
+ /* ignore. A root fiber object will free th->ec */
+ }
+ else {
+ VM_ASSERT(th->ec->fiber->cont.type == ROOT_FIBER_CONTEXT);
+ VM_ASSERT(th->ec->fiber->cont.self == 0);
+ fiber_free(th->ec->fiber);
+
+ if (th->ec == ruby_current_execution_context_ptr) {
+ ruby_current_execution_context_ptr = NULL;
+ }
+ th->ec = NULL;
+ }
+}
+
static inline rb_fiber_t*
fiber_current(void)
{