[Python-checkins] cpython: Issue #24268: Address some PEP 489 refleaks
nick.coghlan
python-checkins at python.org
Sat May 23 17:03:57 CEST 2015
https://hg.python.org/cpython/rev/7f2e6f236202
changeset: 96229:7f2e6f236202
user: Nick Coghlan <ncoghlan at gmail.com>
date: Sun May 24 01:03:46 2015 +1000
summary:
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
files:
Modules/_testmultiphase.c | 1 +
Objects/moduleobject.c | 1 +
Objects/typeobject.c | 15 ++++++++++-----
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -262,6 +262,7 @@
return NULL;
}
PyDict_SetItemString(dct, "three", three);
+ Py_DECREF(three);
ns = _PyNamespace_New(dct);
Py_DECREF(dct);
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -311,6 +311,7 @@
}
}
+ Py_DECREF(nameobj);
return m;
error:
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2694,6 +2694,7 @@
{
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 @@
/* 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))
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list