]> granicus.if.org Git - python/commitdiff
Issue #15394: Fix ref leaks in PyModule_Create.
authorMeador Inge <meadori@gmail.com>
Thu, 19 Jul 2012 18:45:43 +0000 (13:45 -0500)
committerMeador Inge <meadori@gmail.com>
Thu, 19 Jul 2012 18:45:43 +0000 (13:45 -0500)
Patch by Julia Lawall.

Misc/ACKS
Misc/NEWS
Objects/moduleobject.c

index 3bf81a266bccc997391d03f7dff23735c6676542..16847be1f84c330fe5b95572103bc05ef55e82cd 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -542,6 +542,7 @@ Soren Larsen
 Piers Lauder
 Ben Laurie
 Simon Law
+Julia Lawall
 Chris Lawrence
 Brian Leair
 James Lee
index 5793aec6b610f89c3c5b13c2c16d2e084f7d0c46..0136a4425b25eb33df84977cebd5712259130d4b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #15394: An issue in PyModule_Create that caused references to
+  be leaked on some error paths has been fixed.  Patch by Julia Lawall.
+
 - Issue #15368: An issue that caused bytecode generation to be
   non-deterministic when using randomized hashing (-R) has been fixed.
 
index f31b5da26d57eb26092b73414d1ade7d632b46f3..533db46efa81c07c468be97f4c1f7b316bb676f8 100644 (file)
@@ -117,8 +117,10 @@ PyModule_Create2(struct PyModuleDef* module, int module_api_version)
     d = PyModule_GetDict((PyObject*)m);
     if (module->m_methods != NULL) {
         n = PyUnicode_FromString(name);
-        if (n == NULL)
+        if (n == NULL) {
+            Py_DECREF(m);
             return NULL;
+        }
         for (ml = module->m_methods; ml->ml_name != NULL; ml++) {
             if ((ml->ml_flags & METH_CLASS) ||
                 (ml->ml_flags & METH_STATIC)) {
@@ -126,16 +128,19 @@ PyModule_Create2(struct PyModuleDef* module, int module_api_version)
                                 "module functions cannot set"
                                 " METH_CLASS or METH_STATIC");
                 Py_DECREF(n);
+                Py_DECREF(m);
                 return NULL;
             }
             v = PyCFunction_NewEx(ml, (PyObject*)m, n);
             if (v == NULL) {
                 Py_DECREF(n);
+                Py_DECREF(m);
                 return NULL;
             }
             if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
                 Py_DECREF(v);
                 Py_DECREF(n);
+                Py_DECREF(m);
                 return NULL;
             }
             Py_DECREF(v);
@@ -146,6 +151,7 @@ PyModule_Create2(struct PyModuleDef* module, int module_api_version)
         v = PyUnicode_FromString(module->m_doc);
         if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
             Py_XDECREF(v);
+            Py_DECREF(m);
             return NULL;
         }
         Py_DECREF(v);