From 26fa27fe12cab1c9af8401399dba811b6f52803b Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 17 Apr 2015 02:58:37 +0000 Subject: [PATCH] string.c: clear NOFREE flag at embedding * string.c (STR_SET_EMBED): clear NOFREE flag at embedding as embedded strings no longer refer static strings. [ruby-core:68436] [Bug #10942] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ string.c | 2 +- test/-ext-/string/test_nofree.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/-ext-/string/test_nofree.rb diff --git a/ChangeLog b/ChangeLog index 95d1c2031d..45bff0757f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 17 11:58:34 2015 Nobuyoshi Nakada + + * string.c (STR_SET_EMBED): clear NOFREE flag at embedding as + embedded strings no longer refer static strings. + [ruby-core:68436] [Bug #10942] + Thu Apr 16 05:15:50 2015 Eric Wong * NEWS: note IO#wait_readable change in r50263 diff --git a/string.c b/string.c index 29dfdb94af..d85033ea6c 100644 --- a/string.c +++ b/string.c @@ -74,7 +74,7 @@ VALUE rb_cSymbol; FL_SET((str), STR_NOEMBED);\ STR_SET_EMBED_LEN((str), 0);\ } while (0) -#define STR_SET_EMBED(str) FL_UNSET((str), STR_NOEMBED) +#define STR_SET_EMBED(str) FL_UNSET((str), (STR_NOEMBED|STR_NOFREE)) #define STR_SET_EMBED_LEN(str, n) do { \ long tmp_n = (n);\ RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\ diff --git a/test/-ext-/string/test_nofree.rb b/test/-ext-/string/test_nofree.rb new file mode 100644 index 0000000000..cbaabb2d71 --- /dev/null +++ b/test/-ext-/string/test_nofree.rb @@ -0,0 +1,10 @@ +require 'test/unit' + +class Test_StringNoFree < Test::Unit::TestCase + def test_no_memory_leak + bug10942 = '[ruby-core:68436] [Bug #10942] no leak on nofree string' + assert_no_memory_leak(%w(-r-test-/string/string), '', + '1000000.times {Bug::String.nofree << "a" * 100}', + bug10942, rss: true) + end +end