Fix potential memory corruption when jsV_newmemstring fails to allocate.

Don't change the value until the allocation has succeeded.
This commit is contained in:
Tor Andersson
2020-03-17 14:04:07 +01:00
parent 8f12e045f6
commit 90aca80865

View File

@@ -312,8 +312,8 @@ const char *jsV_tostring(js_State *J, js_Value *v)
v->type = JS_TSHRSTR;
return v->u.shrstr;
} else {
v->type = JS_TMEMSTR;
v->u.memstr = jsV_newmemstring(J, p, n);
v->type = JS_TMEMSTR;
return v->u.memstr->p;
}
}