mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
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:
parent
526606baf7
commit
080ee5a884
1 changed files with 10 additions and 5 deletions
|
@ -705,24 +705,29 @@ static PyStatus
|
||||||
pycore_interp_init(PyThreadState *tstate)
|
pycore_interp_init(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
PyStatus status;
|
PyStatus status;
|
||||||
|
PyObject *sysmod = NULL;
|
||||||
|
|
||||||
status = pycore_init_types(tstate);
|
status = pycore_init_types(tstate);
|
||||||
if (_PyStatus_EXCEPTION(status)) {
|
if (_PyStatus_EXCEPTION(status)) {
|
||||||
return status;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *sysmod;
|
|
||||||
status = _PySys_Create(tstate, &sysmod);
|
status = _PySys_Create(tstate, &sysmod);
|
||||||
if (_PyStatus_EXCEPTION(status)) {
|
if (_PyStatus_EXCEPTION(status)) {
|
||||||
return status;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pycore_init_builtins(tstate);
|
status = pycore_init_builtins(tstate);
|
||||||
if (_PyStatus_EXCEPTION(status)) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue