Merge pull request #1846 from jmichelp/master

Avoid memory leaks with Python <3.10
This commit is contained in:
Iceman 2022-12-21 07:54:42 +01:00 committed by GitHub
commit 48827699de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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) {