diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-12 07:36:36 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-12 07:36:36 +0900 |
| commit | be3e36cb0508713d651026597d7320bc9ce8337a (patch) | |
| tree | 64b1d9c5a4c1b9938abb74a67baa91a452637924 /src | |
| parent | d0401dccc4ea5fe7b1769b1f9f86e7900ebde163 (diff) | |
| parent | f1e15b023655bb0c377fada2e26b8361f702d429 (diff) | |
| download | mruby-be3e36cb0508713d651026597d7320bc9ce8337a.tar.gz mruby-be3e36cb0508713d651026597d7320bc9ce8337a.zip | |
Merge pull request #2389 from ksss/str-mem-leaks
Fix memory leaks in String
Diffstat (limited to 'src')
| -rw-r--r-- | src/string.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/string.c b/src/string.c index 92a34e70f..9b5707dc0 100644 --- a/src/string.c +++ b/src/string.c @@ -1368,14 +1368,17 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2) long len; len = RSTR_LEN(s2); + if (RSTR_SHARED_P(s1)) { + str_decref(mrb, s1->as.heap.aux.shared); + } + else if (!RSTR_EMBED_P(s1) && !RSTR_NOFREE_P(s1)) { + mrb_free(mrb, s1->as.heap.ptr); + } + + RSTR_UNSET_NOFREE_FLAG(s1); + if (RSTR_SHARED_P(s2)) { - L_SHARE: - if (RSTR_SHARED_P(s1)) { - str_decref(mrb, s1->as.heap.aux.shared); - } - else if (!RSTR_EMBED_P(s1) && !RSTR_NOFREE_P(s1)) { - mrb_free(mrb, s1->as.heap.ptr); - } +L_SHARE: RSTR_UNSET_EMBED_FLAG(s1); s1->as.heap.ptr = s2->as.heap.ptr; s1->as.heap.len = len; @@ -1385,6 +1388,7 @@ str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2) } else { if (len <= RSTRING_EMBED_LEN_MAX) { + RSTR_UNSET_SHARED_FLAG(s1); RSTR_SET_EMBED_FLAG(s1); memcpy(s1->as.ary, RSTR_PTR(s2), len); RSTR_SET_EMBED_LEN(s1, len); |
