bpo-38858: Fix reference leak in pycore_init_types() (GH-17286)
Only call _PyGC_Init(), _PyExc_Init() and _PyErr_Init() in new_interpreter().
This commit is contained in:
parent
67e0de6f0b
commit
e7e699e4df
|
@ -558,7 +558,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
|||
|
||||
|
||||
static PyStatus
|
||||
pycore_init_types(PyThreadState *tstate)
|
||||
pycore_init_types(PyThreadState *tstate, int is_main_interp)
|
||||
{
|
||||
PyStatus status;
|
||||
|
||||
|
@ -567,6 +567,7 @@ pycore_init_types(PyThreadState *tstate)
|
|||
return status;
|
||||
}
|
||||
|
||||
if (is_main_interp) {
|
||||
status = _PyTypes_Init();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
|
@ -580,12 +581,14 @@ pycore_init_types(PyThreadState *tstate)
|
|||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
status = _PyExc_Init();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (is_main_interp) {
|
||||
if (!_PyFloat_Init()) {
|
||||
return _PyStatus_ERR("can't init float");
|
||||
}
|
||||
|
@ -593,15 +596,18 @@ pycore_init_types(PyThreadState *tstate)
|
|||
if (_PyStructSequence_Init() < 0) {
|
||||
return _PyStatus_ERR("can't initialize structseq");
|
||||
}
|
||||
}
|
||||
|
||||
status = _PyErr_Init();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (is_main_interp) {
|
||||
if (!_PyContext_Init()) {
|
||||
return _PyStatus_ERR("can't init context");
|
||||
}
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
@ -690,7 +696,7 @@ pyinit_config(_PyRuntimeState *runtime,
|
|||
config = &tstate->interp->config;
|
||||
*tstate_p = tstate;
|
||||
|
||||
status = pycore_init_types(tstate);
|
||||
status = pycore_init_types(tstate, 1);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
@ -1477,7 +1483,7 @@ new_interpreter(PyThreadState **tstate_p)
|
|||
}
|
||||
config = &interp->config;
|
||||
|
||||
status = pycore_init_types(tstate);
|
||||
status = pycore_init_types(tstate, 0);
|
||||
|
||||
/* XXX The following is lax in error checking */
|
||||
PyObject *modules = PyDict_New();
|
||||
|
|
Loading…
Reference in New Issue