diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2015-05-23 15:03:46 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2015-05-23 15:03:46 (GMT) |
commit | a48db2bc8b882e887fbe8a84b31828d8491dd877 (patch) | |
tree | 6c23d36fde01e8961bac1d24d6a87334b7c4f465 /Objects | |
parent | d5cacbb1d9c3edc02bf0ba01702e7c06da5bc318 (diff) | |
download | cpython-a48db2bc8b882e887fbe8a84b31828d8491dd877.zip cpython-a48db2bc8b882e887fbe8a84b31828d8491dd877.tar.gz cpython-a48db2bc8b882e887fbe8a84b31828d8491dd877.tar.bz2 |
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
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/moduleobject.c | 1 | ||||
-rw-r--r-- | Objects/typeobject.c | 15 |
2 files changed, 11 insertions, 5 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 7a86a5b..7b41b0b 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -311,6 +311,7 @@ PyModule_FromDefAndSpec2(struct PyModuleDef* def, PyObject *spec, int module_api } } + Py_DECREF(nameobj); return m; error: diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 9522ac5..2f1779f 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2694,6 +2694,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); PyTypeObject *type, *base; + PyObject *modname; char *s; char *res_start = (char*)res; PyType_Slot *slot; @@ -2807,11 +2808,15 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) /* Set type.__module__ */ s = strrchr(spec->name, '.'); - if (s != NULL) - _PyDict_SetItemId(type->tp_dict, &PyId___module__, - PyUnicode_FromStringAndSize( - spec->name, (Py_ssize_t)(s - spec->name))); - else { + if (s != NULL) { + modname = PyUnicode_FromStringAndSize( + spec->name, (Py_ssize_t)(s - spec->name)); + if (modname == NULL) { + goto fail; + } + _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); + Py_DECREF(modname); + } else { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "builtin type %.200s has no __module__ attribute", spec->name)) |