[ruby-cvs:73391] normal:r66290 (trunk): thread_pthread.c: fix memory leak from fork loop leapfrog (v2)

normal at ruby-lang.org normal at ruby-lang.org
Sun Dec 9 06:45:50 JST 2018


normal	2018-12-09 06:45:50 +0900 (Sun, 09 Dec 2018)

  New Revision: 66290

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66290

  Log:
    thread_pthread.c: fix memory leak from fork loop leapfrog (v2)
    
    Constantly forking a single-threaded process in a loop leads to
    a memory leak when using POSIX timers.
    
    v2: disarm before timer_delete
    
    ==> fork_leapfrog.rb <==
    require 'io/wait'
    Dir.chdir '/proc'
    prev = 0
    loop do
      pid = fork
      exit!(0) if pid
    
      # show the number of 4K pages used (Linux-only)
      n = File.read("#$$/statm").split(-' ')[1].to_i
      if n > prev
        puts "#{prev} => #{n}"
        prev = n
      end
    
      # since Ctrl-C from a terminal can't stop this loop,
      # allow the user to just hit any key to stop
      break if STDIN.wait(0)
    end

  Modified files:
    trunk/thread_pthread.c


More information about the ruby-cvs mailing list