clear shared and nofree flags; ref #2370

parent 20dc629b
...@@ -2537,11 +2537,17 @@ mrb_str_clear(mrb_state *mrb, mrb_value str) ...@@ -2537,11 +2537,17 @@ mrb_str_clear(mrb_state *mrb, mrb_value str)
{ {
struct RString *s = mrb_str_ptr(str); struct RString *s = mrb_str_ptr(str);
if (!STR_SHARED_P(s) && !STR_EMBED_P(s) && ((s->flags & MRB_STR_NOFREE) == 0)) { if (!STR_SHARED_P(s) && !STR_EMBED_P(s)) {
mrb_free(mrb, s->as.heap.ptr); if (s->flags & MRB_STR_NOFREE) {
RSTRING(str)->as.heap.ptr = 0; s->flags &= ~MRB_STR_NOFREE;
RSTRING(str)->as.heap.len = 0; }
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_FLAG(s);
STR_SET_EMBED_LEN(s, 0); STR_SET_EMBED_LEN(s, 0);
RSTRING_PTR(str)[0] = '\0'; RSTRING_PTR(str)[0] = '\0';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment