mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
clear shared and nofree flags; ref #2370
This commit is contained in:
+10
-4
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user