ruby-changes:18031
From: naruse <ko1@a...>
Date: Thu, 2 Dec 2010 21:33:37 +0900 (JST)
Subject: [ruby-changes:18031] Ruby:r30052 (trunk): * encoding.c (enc_alias_internal): free the copied key and
naruse 2010-12-02 21:28:42 +0900 (Thu, 02 Dec 2010) New Revision: 30052 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30052 Log: * encoding.c (enc_alias_internal): free the copied key and return NULL when given key is already regisitered. * encoding.c (enc_alias): call set_encoding_const only when the alias is not registered yet. Modified files: trunk/ChangeLog trunk/encoding.c Index: encoding.c =================================================================== --- encoding.c (revision 30051) +++ encoding.c (revision 30052) @@ -436,12 +436,19 @@ return name[0] == 'U' && name[1] == 'T' && name[2] == 'F' && name[4] != '7'; } +/* + * Returns copied alias name when the key is added for st_table, + * else returns NULL. + */ static const char * enc_alias_internal(const char *alias, int idx) { - alias = strdup(alias); - st_insert(enc_table.names, (st_data_t)alias, (st_data_t)idx); - return alias; + char *name = strdup(alias); + if (st_insert(enc_table.names, (st_data_t)name, (st_data_t)idx)) { + free(name); + return NULL; + } + return name; } static int @@ -449,7 +456,7 @@ { if (!valid_encoding_name_p(alias)) return -1; alias = enc_alias_internal(alias, idx); - set_encoding_const(alias, rb_enc_from_index(idx)); + if (alias) set_encoding_const(alias, rb_enc_from_index(idx)); return idx; } Index: ChangeLog =================================================================== --- ChangeLog (revision 30051) +++ ChangeLog (revision 30052) @@ -1,3 +1,11 @@ +Thu Dec 2 21:22:05 2010 NARUSE, Yui <naruse@r...> + + * encoding.c (enc_alias_internal): free the copied key and + return NULL when given key is already regisitered. + + * encoding.c (enc_alias): call set_encoding_const only when the + alias is not registered yet. + Thu Dec 2 19:58:24 2010 URABE Shyouhei <shyouhei@r...> * vm.c (ruby_vm_at_exit): new API. This enables extension libs to -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/