ruby/ruby — pull request #191 by alexdowad (2012-10-11 08:18:24+00:00)
Title: Use RB_GC_GUARD to prevent GC from freeing String copies used by iterators

This fixes the bug which I reported yesterday at: http://bugs.ruby-lang.org/issues/7135

I was having a problem with incorrect values yielded by String#codepoints, because the frozen string copy which it uses internally was being freed by the GC. I noticed that very similar code is used in String#lines and String#chars, so I added RB_GC_GUARD to those also to make sure that similar problems do not happen to anyone when using those methods.