title: Ruby script causes segmentation fault when garbage collector is called
body: <p>I'm having trouble making ruby scripts work that are embedded in C++ code. I noticed that when the program runs for a while the ruby script has a segmentation fault. After some experimentation, I traced this issue to the garbage collector. When the program allocates enough memory that the garbage collector needs to be called, it triggers this segfault. The same result can be achieved with GC.start. Disabling the garbage collection fixes this issue, but it's sort of important to have that running so I can't just disable it like that. Is this a known bug, or am I doing something wrong with my code?</p>
  
  <p>Here is the c++ code</p>
  
  <pre><code>#include &lt;ruby.h&gt;
  
  int main()
  {
  
  //Initialize ruby
  ruby_init();
  ruby_init_loadpath();
  
  //Start main loop in ruby
  int status;
  rb_load_protect(rb_str_new2("./scripts/main.rb"), 0, &amp;status);
  
  //Handle errors
  if (status) 
  {
      VALUE rbError = rb_funcall(rb_gv_get("$!"), rb_intern("message"), 0);
      std::cerr &lt;&lt; StringValuePtr(rbError) &lt;&lt; std::endl;
  }
  
  //Terminate ruby interpreter
  ruby_finalize();
  exit(0);
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the ruby script "main.rb"</p>
  
  <pre><code>begin
  
    running = true
  
    # Main update loop
    while (running == true)
  
      var = "foo"
  
      sleep 0.01
  
    end
  
  end
  </code></pre>
  
  <p>The 'var = "foo"' statement is just to demonstrate the problem. When this statement is called enough times and enough memory is allocated, the GC kicks in and the program crashes.</p>