Skip to content
  • Peter Zhu's avatar
    51ffef28
    Fix memory leak in prism when syntax error in iseq compilation · 51ffef28
    Peter Zhu authored
    If there's a syntax error during iseq compilation then prism would leak
    memory because it would not free the pm_parse_result_t.
    
    This commit changes pm_iseq_new_with_opt to have a rb_protect to catch
    when an error is raised, and return NULL and set error_state to a value
    that can be raised by calling rb_jump_tag after memory has been freed.
    
    For example:
    
        10.times do
          10_000.times do
            eval("/[/=~s")
          rescue SyntaxError
          end
    
          puts `ps -o rss= -p #{$$}`
        end
    
    Before:
    
        39280
        68736
        99232
        128864
        158896
        188208
        217344
        246304
        275376
        304592
    
    After:
    
        12192
        13200
        14256
        14848
        16000
        16000
        16000
        16064
        17232
        17952
    51ffef28
    Fix memory leak in prism when syntax error in iseq compilation
    Peter Zhu authored
    If there's a syntax error during iseq compilation then prism would leak
    memory because it would not free the pm_parse_result_t.
    
    This commit changes pm_iseq_new_with_opt to have a rb_protect to catch
    when an error is raised, and return NULL and set error_state to a value
    that can be raised by calling rb_jump_tag after memory has been freed.
    
    For example:
    
        10.times do
          10_000.times do
            eval("/[/=~s")
          rescue SyntaxError
          end
    
          puts `ps -o rss= -p #{$$}`
        end
    
    Before:
    
        39280
        68736
        99232
        128864
        158896
        188208
        217344
        246304
        275376
        304592
    
    After:
    
        12192
        13200
        14256
        14848
        16000
        16000
        16000
        16064
        17232
        17952
Loading