bpo-38858: Fix ref leak in pycore_interp_init() (GH-17512)

bpo-38858, bpo-38997: _PySys_Create() returns a strong reference to
the sys module: Py_DECREF() is needed when we are done with the
module.
This commit is contained in:
Victor Stinner 2019-12-08 21:55:58 +01:00 committed by GitHub
parent 526606baf7
commit 080ee5a884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -705,24 +705,29 @@ static PyStatus
pycore_interp_init(PyThreadState *tstate)
{
PyStatus status;
PyObject *sysmod = NULL;
status = pycore_init_types(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
goto done;
}
PyObject *sysmod;
status = _PySys_Create(tstate, &sysmod);
if (_PyStatus_EXCEPTION(status)) {
return status;
goto done;
}
status = pycore_init_builtins(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
goto done;
}
return pycore_init_import_warnings(tstate, sysmod);
status = pycore_init_import_warnings(tstate, sysmod);
done:
/* sys.modules['sys'] contains a strong reference to the module */
Py_XDECREF(sysmod);
return status;
}