From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] stringio: avoid STR_NOFREE due to constant string
Date: Fri, 17 Apr 2015 01:40:01 +0000 [thread overview]
Message-ID: <1429234801-25326-1-git-send-email-e@80x24.org> (raw)
---
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
reply other threads:[~2015-04-17 1:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429234801-25326-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).