From 683400f4278fe0db00592c06522979be845bcc45 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 10 Nov 2004 07:17:53 +0000 Subject: * dir.c (rb_glob2): do not allocate buffer from heap to avoid memory leaks. use string object for buffering instead. [ruby-dev:24738] * dir.c (join_path): ditto. * io.c (io_read): external input buffer may be modified even after rb_str_locktmp(). [ruby-dev:24735] * dir.c (fnmatch): p or s may be NULL. [ruby-dev:24749] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index ac3efa3c5f..3df8fb9555 100644 --- a/string.c +++ b/string.c @@ -252,13 +252,6 @@ rb_str_shared_replace(str, str2) if (str == str2) return; rb_str_modify(str); if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr); - if (NIL_P(str2)) { - RSTRING(str)->ptr = 0; - RSTRING(str)->len = 0; - RSTRING(str)->aux.capa = 0; - FL_UNSET(str, STR_NOCAPA); - return; - } RSTRING(str)->ptr = RSTRING(str2)->ptr; RSTRING(str)->len = RSTRING(str2)->len; FL_UNSET(str, STR_NOCAPA); @@ -640,6 +633,9 @@ VALUE rb_str_locktmp(str) VALUE str; { + if (FL_TEST(str, STR_TMPLOCK)) { + rb_raise(rb_eRuntimeError, "temporal locking already locked string"); + } FL_SET(str, STR_TMPLOCK); return str; } @@ -648,6 +644,9 @@ VALUE rb_str_unlocktmp(str) VALUE str; { + if (!FL_TEST(str, STR_TMPLOCK)) { + rb_raise(rb_eRuntimeError, "temporal unlocking already unlocked string"); + } FL_UNSET(str, STR_TMPLOCK); return str; } @@ -2278,7 +2277,8 @@ rb_str_clear(str) } RSTRING(str)->aux.shared = 0; FL_UNSET(str, STR_NOCAPA); - RSTRING(str)->ptr = 0; + FL_SET(str, ELTS_SHARED); + RSTRING(str)->ptr = null_str; RARRAY(str)->len = 0; return str; } -- cgit v1.2.3