/
04-backport-20ef4699e510f89ad4e9ccbeafa2d3d725ed2d3c.patch
48 lines (48 loc) · 1.39 KB
/
04-backport-20ef4699e510f89ad4e9ccbeafa2d3d725ed2d3c.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
diff --git a/ext/-test-/string/nofree.c b/ext/-test-/string/nofree.c
new file mode 100644
index 0000000..d3d8071
--- /dev/null
+++ b/ext/-test-/string/nofree.c
@@ -0,0 +1,13 @@
+#include "ruby.h"
+
+VALUE
+bug_str_nofree(VALUE self)
+{
+ return rb_str_new_cstr("abcdef");
+}
+
+void
+Init_nofree(VALUE klass)
+{
+ rb_define_singleton_method(klass, "nofree", bug_str_nofree, 0);
+}
diff --git a/string.c b/string.c
index 2652b29..1753b37 100644
--- a/string.c
+++ b/string.c
@@ -60,7 +60,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 0000000..234c84d
--- /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, limit: 2.0)
+ end
+end