"".clear dumps core

e$B1sF#$H?=$7$^$9!#e(B

1.9 e$B$G0J2<$N$h$&$K$9$k$HMn$A$^$9!#e(B

$ ./ruby -e ‘"".clear’
*** glibc detected *** free(): invalid pointer: 0xb7ce7ebc ***
e$B%"%!<%H$7$^$7$?e(B (core dumped)

e$BB>$N$H$3$m$N%3!<%I$+$i?dB,$9$k$K!"$3$s$J46$8$G$7$g$&$+!#e(B
e$B$O$:$l$F$?$i$4$a$s$J$5$$!#e(B

Index: string.c

— string.c (revision 12629)
+++ string.c (working copy)
@@ -2347,7 +2347,7 @@
rb_str_clear(VALUE str)
{
/* rb_str_modify() / / no need for str_make_independent */

  • if (str_independent(str)) {
  • if (str_independent(str) && !STR_EMBED_P(str)) {
    free(RSTRING_PTR(str));
    }
    STR_SET_EMBED(str);