Desciption: Deal with the "use after free" error

occurs while debugging ark_js_vm executable on
windows.

Details: Enclose the part where the LocalScope
object should take effect with a pair of braces.
Thus, the destructor of the LocalScope object
will be called at the right brace which is above
the JSNApi::DestroyJSVM() function.

Issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5C7XG

Signed-off-by: Gongyuhang <gongyuhang5@huawei.com>
This commit is contained in:
Gongyuhang 2022-06-14 16:13:59 +08:00
parent 43e0608f7d
commit 496687fe52
2 changed files with 34 additions and 29 deletions

View File

@ -110,6 +110,7 @@ int Main(const int argc, const char **argv)
return -1;
}
{
LocalScope scope(vm);
std::string entry = entrypoint.GetValue();
arg_list_t pandaFileNames = files.GetValue();
@ -133,6 +134,8 @@ int Main(const int argc, const char **argv)
}
generator.SaveAOTFile(outputFileName);
generator.GenerateSnapshotFile();
}
JSNApi::DestroyJSVM(vm);
paParser.DisableTail();
return ret ? 0 : -1;

View File

@ -109,6 +109,7 @@ int Main(const int argc, const char **argv)
return -1;
}
{
LocalScope scope(vm);
std::string entry = entrypoint.GetValue();
@ -121,6 +122,7 @@ int Main(const int argc, const char **argv)
break;
}
}
}
JSNApi::DestroyJSVM(vm);
paParser.DisableTail();