Make sure to clean up memory after a Python exception
This commit is contained in:
parent
01255bdf6c
commit
47c1089c61
1 changed files with 12 additions and 2 deletions
|
|
@ -255,12 +255,22 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
|
||||||
std::strcpy(argv[i + 1], arg.c_str());
|
std::strcpy(argv[i + 1], arg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = Py_Main(static_cast<int>(args.size()) + 1, argv);
|
int status;
|
||||||
|
|
||||||
|
try {
|
||||||
|
status = Py_Main(static_cast<int>(args.size()) + 1, argv);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
for (std::size_t i = 0; i < args.size() + 1; i++)
|
||||||
|
delete[] argv[i];
|
||||||
|
delete[] argv;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
for (std::size_t i = 0; i < args.size() + 1; i++)
|
for (std::size_t i = 0; i < args.size() + 1; i++)
|
||||||
delete[] argv[i];
|
delete[] argv[i];
|
||||||
delete[] argv;
|
delete[] argv;
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
throw status;
|
throw status;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue