Issue #24268: Address some PEP 489 refleaks
- missing DECREF in PyModule_FromDefAndSpec2 - missing DECREF in PyType_FromSpecAndBases2 - missing DECREF in _testmultiphase module Patch by Petr Viktorin
This commit is contained in:
parent
d5cacbb1d9
commit
a48db2bc8b
|
@ -262,6 +262,7 @@ createfunc_nonmodule(PyObject *spec, PyModuleDef *def)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(dct, "three", three);
|
PyDict_SetItemString(dct, "three", three);
|
||||||
|
Py_DECREF(three);
|
||||||
|
|
||||||
ns = _PyNamespace_New(dct);
|
ns = _PyNamespace_New(dct);
|
||||||
Py_DECREF(dct);
|
Py_DECREF(dct);
|
||||||
|
|
|
@ -311,6 +311,7 @@ PyModule_FromDefAndSpec2(struct PyModuleDef* def, PyObject *spec, int module_api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Py_DECREF(nameobj);
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
|
@ -2694,6 +2694,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
|
||||||
{
|
{
|
||||||
PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
|
PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
|
||||||
PyTypeObject *type, *base;
|
PyTypeObject *type, *base;
|
||||||
|
PyObject *modname;
|
||||||
char *s;
|
char *s;
|
||||||
char *res_start = (char*)res;
|
char *res_start = (char*)res;
|
||||||
PyType_Slot *slot;
|
PyType_Slot *slot;
|
||||||
|
@ -2807,11 +2808,15 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
|
||||||
|
|
||||||
/* Set type.__module__ */
|
/* Set type.__module__ */
|
||||||
s = strrchr(spec->name, '.');
|
s = strrchr(spec->name, '.');
|
||||||
if (s != NULL)
|
if (s != NULL) {
|
||||||
_PyDict_SetItemId(type->tp_dict, &PyId___module__,
|
modname = PyUnicode_FromStringAndSize(
|
||||||
PyUnicode_FromStringAndSize(
|
spec->name, (Py_ssize_t)(s - spec->name));
|
||||||
spec->name, (Py_ssize_t)(s - spec->name)));
|
if (modname == NULL) {
|
||||||
else {
|
goto fail;
|
||||||
|
}
|
||||||
|
_PyDict_SetItemId(type->tp_dict, &PyId___module__, modname);
|
||||||
|
Py_DECREF(modname);
|
||||||
|
} else {
|
||||||
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
|
||||||
"builtin type %.200s has no __module__ attribute",
|
"builtin type %.200s has no __module__ attribute",
|
||||||
spec->name))
|
spec->name))
|
||||||
|
|
Loading…
Reference in New Issue