Gsub! memory leak

e$BIMCO$H$$$$$^$9!#e(B

yarvtest/runner.rb e$B$,e(B valgrind e$B$KE$i$l$k$h$&$J$N$Ge(B
[email protected]$7$F$$^$7$?!#0J2<$G:F8=$9$k$$?$$$G$9!#e(B

% cat leak.rb
val = ‘$(RUBY_SO_NAME)-static.a’
val.gsub!(/RUBY_SO_NAME/, ‘h’)
% valgrind --leak-check=full ./ruby1.9 leak.rb

Index: string.c

— string.c (revision 18321)
+++ string.c (working copy)
@@ -617,6 +617,9 @@
cr = ENC_CODERANGE(str2);
rb_str_modify(str);
if (OBJ_TAINTED(str2)) OBJ_TAINT(str);

  • if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
  • xfree(RSTRING_PTR(str));
  • }
    if (RSTRING_LEN(str2) <= RSTRING_EMBED_LEN_MAX) {
    STR_SET_EMBED(str);
    memcpy(RSTRING_PTR(str), RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
    @@ -625,9 +628,6 @@
    ENC_CODERANGE_SET(str, cr);
    return;
    }
  • if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
  • xfree(RSTRING_PTR(str));
  • }
    STR_SET_NOEMBED(str);
    STR_UNSET_NOCAPA(str);
    RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs