Avoid memory leaks with Python <3.10

This commit is contained in:
Jean-Michel Picod 2022-12-20 15:32:38 +01:00
parent da3fff58fa
commit 4375f5b91e

View file

@ -426,8 +426,6 @@ static int CmdScriptRun(const char *Cmd) {
}
PySys_SetArgv(argc + 1, py_args);
// clean up
#else
// The following line will implicitly pre-initialize Python
PyConfig_SetBytesArgv(&py_conf, argc + 1, argv);
@ -453,6 +451,12 @@ static int CmdScriptRun(const char *Cmd) {
return PM3_ESOFT;
}
int ret = Pm3PyRun_SimpleFileNoExit(f, filename);
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10
// Py_DecodeLocale() allocates memory that needs to be free'd
for (int i = 0; i < argc + 1; i++) {
PyMem_RawFree(py_args[i]);
}
#endif
Py_Finalize();
free(script_path);
if (ret) {