aboutsummaryrefslogtreecommitdiffstats
path: root/cont.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-07-19 11:09:52 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-07-19 11:10:01 +1200
commitd7fdf45a4ae1bcb6fac30a24b025d4f20149ba0a (patch)
tree983309ca564439ec223dd4c6388e195ce277190e /cont.c
parent9dda0a03cc19d0ca20fc8fc220760e37cb5b9f02 (diff)
downloadruby-d7fdf45a4ae1bcb6fac30a24b025d4f20149ba0a.tar.gz
Ensure cfp is initialized to NULL.
`cont_init` didn't initialize `cont->saved_ec.cfp`. Calling `cont_mark` would result in an invalid `cfp` in `rb_execution_context_mark`. Because fibers lazy-initialize the stack, fibers that are created but not resumed could cause this problem to occur.
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/cont.c b/cont.c
index c0be42bffc..984733db6e 100644
--- a/cont.c
+++ b/cont.c
@@ -845,6 +845,8 @@ cont_mark(void *ptr)
RUBY_MARK_ENTER("cont");
rb_gc_mark_no_pin(cont->value);
+ // Don't try to scan the vm_stack unless it's initialized.
+ // @sa cont_init, fiber_prepare_stack
if (cont->saved_ec.cfp) {
rb_execution_context_mark(&cont->saved_ec);
}
@@ -1083,6 +1085,10 @@ cont_init(rb_context_t *cont, rb_thread_t *th)
{
/* save thread context */
cont_save_thread(cont, th);
+
+ // cfp is not valid until stack is initialized.
+ cont->saved_ec.cfp = NULL;
+
cont->saved_ec.thread_ptr = th;
cont->saved_ec.local_storage = NULL;
cont->saved_ec.local_storage_recursive_hash = Qnil;