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

normal at ruby-lang.org normal at ruby-lang.org
Sun Dec 9 04:25:37 JST 2018


normal	2018-12-09 04:25:37 +0900 (Sun, 09 Dec 2018)

  New Revision: 66288

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

  Log:
    thread_pthread.c: fix memory leak from fork loop leapfrog
    
    Constantly forking a single-threaded process in a loop leads to
    a memory leak when using POSIX timers.
    
    ==> 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