From 99bed88c85e15704f6b9015133ce33d03b7fa061 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 29 Aug 2006 10:11:27 +0000 Subject: [PATCH] * hash.c (rb_hash_s_create): fixed memory leak, based on the patch by Kent Sibilev . fixed: [ruby-talk:211233] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ hash.c | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72fcbf8991..435a9b184f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Aug 29 19:10:10 2006 Nobuyoshi Nakada + + * hash.c (rb_hash_s_create): fixed memory leak, based on the patch + by Kent Sibilev . fixed: [ruby-talk:211233] + Mon Aug 28 11:29:46 2006 Eric Hodel * eval.c, parse.y: Revert. diff --git a/hash.c b/hash.c index 4afba8b624..7a3035f6df 100644 --- a/hash.c +++ b/hash.c @@ -197,17 +197,26 @@ rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg) } static VALUE -hash_alloc(VALUE klass) +hash_alloc0(VALUE klass) { NEWOBJ(hash, struct RHash); OBJSETUP(hash, klass, T_HASH); hash->ifnone = Qnil; - hash->tbl = st_init_table(&objhash); return (VALUE)hash; } +static VALUE +hash_alloc(VALUE klass) +{ + VALUE hash = hash_alloc0(klass); + + RHASH(hash)->tbl = st_init_table(&objhash); + + return hash; +} + VALUE rb_hash_new(void) { @@ -299,9 +308,7 @@ rb_hash_s_create(int argc, VALUE *argv, VALUE klass) int i; if (argc == 1 && TYPE(argv[0]) == T_HASH) { - hash = hash_alloc(klass); - - RHASH(hash)->ifnone = Qnil; + hash = hash_alloc0(klass); RHASH(hash)->tbl = st_copy(RHASH(argv[0])->tbl); return hash; @@ -1644,6 +1651,7 @@ rb_env_path_tainted(void) return path_tainted; } +#if !defined(_WIN32) && !(defined(HAVE_SETENV) && defined(HAVE_UNSETENV)) static int envix(const char *nam) { @@ -1664,6 +1672,7 @@ envix(const char *nam) FREE_ENVIRON(environ); return i; } +#endif void ruby_setenv(const char *name, const char *value)