mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c (rb_hash_rehash): fix to free new st_table when exception
is raised in do_hash(). [Bug #9187] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
64ac49e6fe
commit
bfbe1b9b31
2 changed files with 37 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Dec 1 14:15:36 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||||
|
|
||||||
|
* hash.c (rb_hash_rehash): fix to free new st_table when exception
|
||||||
|
is raised in do_hash(). [Bug #9187]
|
||||||
|
|
||||||
Sun Dec 1 11:57:59 2013 Zachary Scott <e@zzak.io>
|
Sun Dec 1 11:57:59 2013 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
* ext/openssl/lib/openssl/buffering.rb: Fix warning in copyright
|
* ext/openssl/lib/openssl/buffering.rb: Fix warning in copyright
|
||||||
|
|
39
hash.c
39
hash.c
|
@ -576,6 +576,11 @@ rb_hash_s_try_convert(VALUE dummy, VALUE hash)
|
||||||
return rb_check_hash_type(hash);
|
return rb_check_hash_type(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct rehash_arg {
|
||||||
|
VALUE hash;
|
||||||
|
st_table *tbl;
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
|
rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
|
||||||
{
|
{
|
||||||
|
@ -585,6 +590,14 @@ rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rehash_func(VALUE arg)
|
||||||
|
{
|
||||||
|
struct rehash_arg *p = (struct rehash_arg *)arg;
|
||||||
|
rb_hash_foreach(p->hash, rb_hash_rehash_i, (VALUE)p->tbl);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* hsh.rehash -> hsh
|
* hsh.rehash -> hsh
|
||||||
|
@ -608,18 +621,30 @@ rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_hash_rehash(VALUE hash)
|
rb_hash_rehash(VALUE hash)
|
||||||
{
|
{
|
||||||
st_table *tbl;
|
int state;
|
||||||
|
struct rehash_arg arg;
|
||||||
|
st_table *new_tbl, *old_tbl = RHASH(hash)->ntbl;
|
||||||
|
|
||||||
if (RHASH_ITER_LEV(hash) > 0) {
|
if (RHASH_ITER_LEV(hash) > 0) {
|
||||||
rb_raise(rb_eRuntimeError, "rehash during iteration");
|
rb_raise(rb_eRuntimeError, "rehash during iteration");
|
||||||
}
|
}
|
||||||
rb_hash_modify_check(hash);
|
rb_hash_modify_check(hash);
|
||||||
if (!RHASH(hash)->ntbl)
|
if (!old_tbl) return hash;
|
||||||
return hash;
|
|
||||||
tbl = st_init_table_with_size(RHASH(hash)->ntbl->type, RHASH(hash)->ntbl->num_entries);
|
new_tbl = st_init_table_with_size(old_tbl->type, old_tbl->num_entries);
|
||||||
rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tbl);
|
arg.hash = hash;
|
||||||
st_free_table(RHASH(hash)->ntbl);
|
arg.tbl = new_tbl;
|
||||||
RHASH(hash)->ntbl = tbl;
|
|
||||||
|
rb_protect(rehash_func, (VALUE)&arg, &state);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
st_free_table(new_tbl);
|
||||||
|
rb_jump_tag(state);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
st_free_table(RHASH(hash)->ntbl);
|
||||||
|
RHASH(hash)->ntbl = new_tbl;
|
||||||
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue