Skip to content

Commit

Permalink
Check that object is live in each_object
Browse files Browse the repository at this point in the history
Fixes crash in:

    10_000.times.map do
      Object.new
    end

    run_gc = true

    ObjectSpace.each_object do |o|
      if run_gc
        GC.start
        run_gc = false
      end
      puts o
    end
  • Loading branch information
peterzhu2118 committed Oct 22, 2024
1 parent f330782 commit 4d9fa68
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gc/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ each_object(struct objspace *objspace, int (*func)(VALUE, void *), void *data)

VALUE *obj_ptr;
rb_darray_foreach(objs, i, obj_ptr) {
if (!mmtk_is_live_object((MMTk_ObjectReference)*obj_ptr)) continue;

if (func(*obj_ptr, data) != 0) {
break;
}
Expand Down

0 comments on commit 4d9fa68

Please sign in to comment.