Skip to content

Commit

Permalink
rb_gc_register_address() must be called after the variable was assigned
Browse files Browse the repository at this point in the history
* Otherwise the GC might read the variable when it is not pointing
  to a Ruby object yet.
* TruffleRuby also assumes it can read the pointer when
  rb_gc_register_address() is called: oracle/truffleruby#2720
  • Loading branch information
eregon committed Sep 7, 2022
1 parent 6607e64 commit 7d9241a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/sqlite3/aggregator.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
void
rb_sqlite3_aggregator_init(void)
{
rb_gc_register_address(&cAggregatorWrapper);
rb_gc_register_address(&cAggregatorInstance);
/* rb_class_new generatos class with undefined allocator in ruby 1.9 */
cAggregatorWrapper = rb_funcall(rb_cClass, rb_intern("new"), 0);
cAggregatorInstance = rb_funcall(rb_cClass, rb_intern("new"), 0);

rb_gc_register_address(&cAggregatorWrapper);
rb_gc_register_address(&cAggregatorInstance);
}

0 comments on commit 7d9241a

Please sign in to comment.