From 28b9619bb4c1a560392e0f958a5a5d9cedf12bc7 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sun, 3 Jun 2012 15:45:06 +0900 Subject: should decref shared string body on gc_free --- src/string.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/string.c') diff --git a/src/string.c b/src/string.c index 8bc299987..6eba9cb20 100644 --- a/src/string.c +++ b/src/string.c @@ -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); } } -- cgit v1.2.3