Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add missing lock in rb_gc_impl_undefine_finalizer #13349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2774,7 +2774,11 @@ rb_gc_impl_undefine_finalizer(void *objspace_ptr, VALUE obj)
GC_ASSERT(!OBJ_FROZEN(obj));

st_data_t data = obj;

int lev = rb_gc_vm_lock();
st_delete(finalizer_table, &data, 0);
rb_gc_vm_unlock(lev);

FL_UNSET(obj, FL_FINALIZE);
}

Expand Down
4 changes: 4 additions & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,11 @@ rb_gc_impl_undefine_finalizer(void *objspace_ptr, VALUE obj)
struct objspace *objspace = objspace_ptr;

st_data_t data = obj;

int lev = rb_gc_vm_lock();
st_delete(objspace->finalizer_table, &data, 0);
rb_gc_vm_unlock(lev);

FL_UNSET(obj, FL_FINALIZE);
}

Expand Down
19 changes: 19 additions & 0 deletions test/objspace/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,23 @@ def test_tracing_does_not_crash
end
RUBY
end

def test_undefine_finalizer
assert_ractor(<<~'RUBY', require: 'objspace')
def fin
->(id) { }
end
ractors = 5.times.map do
Ractor.new do
10_000.times do
o = Object.new
ObjectSpace.define_finalizer(o, fin)
ObjectSpace.undefine_finalizer(o)
end
end
end

ractors.each(&:take)
RUBY
end
end
Loading