should decref shared string body on gc_free

This commit is contained in:
Yukihiro Matsumoto
2012-06-03 15:45:06 +09:00
parent 60e8d80fa7
commit 28b9619bb4
3 changed files with 15 additions and 6 deletions
+11 -5
View File
@@ -43,6 +43,16 @@ static mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len)
s->aux.capa = capacity;\
} while (0)
void
mrb_str_decref(mrb_state *mrb, struct mrb_shared_string *shared)
{
shared->refcnt--;
if (shared->refcnt == 0) {
mrb_free(mrb, shared->buf);
mrb_free(mrb, shared);
}
}
static void
str_modify(mrb_state *mrb, struct RString *s)
{
@@ -63,11 +73,7 @@ str_modify(mrb_state *mrb, struct RString *s)
s->aux.capa = len;
s->flags &= ~MRB_STR_SHARED;
shared->refcnt--;
if (shared->refcnt == 0) {
mrb_free(mrb, shared->buf);
mrb_free(mrb, shared);
}
mrb_str_decref(mrb, shared);
}
}