dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] stringio: avoid STR_NOFREE due to constant string
@ 2015-04-17  1:40 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-04-17  1:40 UTC (permalink / raw)
  To: spew

---
 ext/stringio/stringio.c        | 2 +-
 test/stringio/test_stringio.rb | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index ed141dd..4679d78 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -208,7 +208,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
 	ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
 	break;
       case 0:
-	string = rb_enc_str_new("", 0, rb_default_external_encoding());
+	string = rb_enc_str_new(0, 0, rb_default_external_encoding());
 	ptr->flags = FMODE_READWRITE;
 	break;
     }
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 966bbe1..853f080 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -586,4 +586,10 @@ class TestStringIO < Test::Unit::TestCase
     assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line(0){} }
     assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line("a",0){} }
   end
+
+  def test_no_leak_on_malloced_string
+    assert_no_memory_leak(%w(-rstringio), 'str = " " * 24',
+                          '1000000.times { StringIO.new << str }',
+                          'no leak on malloced string')
+  end
 end
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-17  1:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-17  1:40 [PATCH] stringio: avoid STR_NOFREE due to constant string Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).