]> granicus.if.org Git - python/commitdiff
Issue #24268: Address some PEP 489 refleaks
authorNick Coghlan <ncoghlan@gmail.com>
Sat, 23 May 2015 15:03:46 +0000 (01:03 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sat, 23 May 2015 15:03:46 +0000 (01:03 +1000)
- missing DECREF in PyModule_FromDefAndSpec2
- missing DECREF in PyType_FromSpecAndBases2
- missing DECREF in _testmultiphase module

Patch by Petr Viktorin

Modules/_testmultiphase.c
Objects/moduleobject.c
Objects/typeobject.c

index 3e8e5d5c6cfa19055faf363b85cee795fa53ba3d..0d50db2f023db34a56a542374d7998e23bd2b520 100644 (file)
@@ -262,6 +262,7 @@ createfunc_nonmodule(PyObject *spec, PyModuleDef *def)
         return NULL;
     }
     PyDict_SetItemString(dct, "three", three);
+    Py_DECREF(three);
 
     ns = _PyNamespace_New(dct);
     Py_DECREF(dct);
index 7a86a5b36fa023b9d2b6b5040dfeccbde1f440f0..7b41b0b6c474f33659a9cdc9a43eb8e6ff1060ee 100644 (file)
@@ -311,6 +311,7 @@ PyModule_FromDefAndSpec2(struct PyModuleDef* def, PyObject *spec, int module_api
         }
     }
 
+    Py_DECREF(nameobj);
     return m;
 
 error:
index 9522ac5809f259689ea8d5cdd747055510f7ac82..2f1779f97046d185dbfe5e9f06fadf1e27c9d7fa 100644 (file)
@@ -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))