diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-07 17:24:18 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-07 17:24:18 +0900 |
| commit | b0c90141d97d8c44cd6778d9c47eb785e128b777 (patch) | |
| tree | 5a53daae1c2d069cd7942b790f4eb42418a6b756 /src/string.c | |
| parent | 20dc629b11cb5cb650bd6826e0e789cf887d1e74 (diff) | |
| download | mruby-b0c90141d97d8c44cd6778d9c47eb785e128b777.tar.gz mruby-b0c90141d97d8c44cd6778d9c47eb785e128b777.zip | |
clear shared and nofree flags; ref #2370
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c index fc5d43612..82f647db1 100644 --- a/src/string.c +++ b/src/string.c @@ -2537,11 +2537,17 @@ mrb_str_clear(mrb_state *mrb, mrb_value str) { struct RString *s = mrb_str_ptr(str); - if (!STR_SHARED_P(s) && !STR_EMBED_P(s) && ((s->flags & MRB_STR_NOFREE) == 0)) { - mrb_free(mrb, s->as.heap.ptr); - RSTRING(str)->as.heap.ptr = 0; - RSTRING(str)->as.heap.len = 0; + if (!STR_SHARED_P(s) && !STR_EMBED_P(s)) { + if (s->flags & MRB_STR_NOFREE) { + s->flags &= ~MRB_STR_NOFREE; + } + else { + mrb_free(mrb, s->as.heap.ptr); + } + s->as.heap.ptr = 0; + s->as.heap.len = 0; } + STR_UNSET_SHARED_FLAG(s); STR_SET_EMBED_FLAG(s); STR_SET_EMBED_LEN(s, 0); RSTRING_PTR(str)[0] = '\0'; |
