Skip to content
  • Peter Zhu's avatar
    516a6cd1
    Check whether object is valid in allocation_info_tracer_compact · 516a6cd1
    Peter Zhu authored
    When reference updating ObjectSpace.trace_object_allocations, we need to
    check whether the object is valid or not because it does not mark the
    object so the object may be dead. This can cause a segmentation fault
    if the object is on a free heap page.
    
    For example, the following script crashes:
    
        require "objspace"
    
        objs = []
        ObjectSpace.trace_object_allocations do
          1_000_000.times do
            objs << Object.new
          end
        end
    
        objs = nil
    
        # Free pages that the objs were on
        GC.start
    
        # Run compaction and check that it doesn't crash
        GC.compact
    516a6cd1
    Check whether object is valid in allocation_info_tracer_compact
    Peter Zhu authored
    When reference updating ObjectSpace.trace_object_allocations, we need to
    check whether the object is valid or not because it does not mark the
    object so the object may be dead. This can cause a segmentation fault
    if the object is on a free heap page.
    
    For example, the following script crashes:
    
        require "objspace"
    
        objs = []
        ObjectSpace.trace_object_allocations do
          1_000_000.times do
            objs << Object.new
          end
        end
    
        objs = nil
    
        # Free pages that the objs were on
        GC.start
    
        # Run compaction and check that it doesn't crash
        GC.compact
Loading