summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-03 01:41:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-03 01:41:56 +0000
commit7f9616097e3187c554ec3de87d1ae4da4337f1fa (patch)
treeab7fd94a15f5377ec52c32144b479991bb41b2db
parent2bd3131bf8c6c9312efa75d0c265c30fd0d6b91c (diff)
downloadruby-7f9616097e3187c554ec3de87d1ae4da4337f1fa.tar.gz
ruby-7f9616097e3187c554ec3de87d1ae4da4337f1fa.tar.xz
ruby-7f9616097e3187c554ec3de87d1ae4da4337f1fa.zip
* string.c (rb_str_shared_replace): fixed memory leak. a patch from
shinichiro.h <shinichiro.hamaji AT gmail.com> at [ruby-dev:35742] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--string.c8
2 files changed, 9 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 19ad28d58..ae62e0f01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Aug 3 10:41:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_shared_replace): fixed memory leak. a patch from
+ shinichiro.h <shinichiro.hamaji AT gmail.com> at [ruby-dev:35742]
+
Sat Aug 2 22:55:41 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_err_in_callback.rb: remove temporary files.
diff --git a/string.c b/string.c
index c031063ac..0231109f6 100644
--- a/string.c
+++ b/string.c
@@ -616,7 +616,10 @@ rb_str_shared_replace(VALUE str, VALUE str2)
enc = STR_ENC_GET(str2);
cr = ENC_CODERANGE(str2);
rb_str_modify(str);
- if (OBJ_TAINTED(str2)) OBJ_TAINT(str);
+ OBJ_INFECT(str, str2);
+ if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
+ xfree(RSTRING_PTR(str));
+ }
if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
STR_SET_EMBED(str);
memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
@@ -625,9 +628,6 @@ rb_str_shared_replace(VALUE str, VALUE str2)
ENC_CODERANGE_SET(str, cr);
return;
}
- if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
- xfree(RSTRING_PTR(str));
- }
STR_SET_NOEMBED(str);
STR_UNSET_NOCAPA(str);
RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);