Fix JS_EncodeStringToUTF8 memory leak

This commit is contained in:
pandamicro
2017-09-01 18:07:14 +08:00
parent 83cd6f465b
commit 97b52f38cb
2 changed files with 10 additions and 4 deletions
@@ -1041,8 +1041,13 @@ void ScriptingCore::reportError(JSContext *cx, JSErrorReport *report, JS::Handle
if (JS_GetProperty(cx, errObj, "stack", &stack) && stack.isString())
{
JS::RootedString jsstackStr(cx, stack.toString());
stackStr = JS_EncodeStringToUTF8(cx, jsstackStr);
CCLOGERROR("Stack: %s\n", stackStr.c_str());
char *rawStr = JS_EncodeStringToUTF8(cx, jsstackStr);
if (rawStr != nullptr)
{
stackStr = rawStr;
JS_free(cx, rawStr);
CCLOGERROR("Stack: %s\n", stackStr.c_str());
}
}
}