summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-12-08 20:55:58 (GMT)
committerGitHub <noreply@github.com>2019-12-08 20:55:58 (GMT)
commit080ee5a88406fb68aaab741145cd5d2a7c5f2ad6 (patch)
treefe03b0e8a3e8b5f7e758c2f6363ec0f989304aa3 /Python
parent526606baf76e7a5309bb00f3bfaefa861a2014ba (diff)
downloadcpython-080ee5a88406fb68aaab741145cd5d2a7c5f2ad6.zip
cpython-080ee5a88406fb68aaab741145cd5d2a7c5f2ad6.tar.gz
cpython-080ee5a88406fb68aaab741145cd5d2a7c5f2ad6.tar.bz2
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 8bd71a3..823d96e 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -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;
}