From 29e49d63942cc75ead85a4cb77dea34285be9fcc Mon Sep 17 00:00:00 2001 From: Meador Inge Date: Thu, 19 Jul 2012 13:45:43 -0500 Subject: Issue #15394: Fix ref leaks in PyModule_Create. Patch by Julia Lawall. --- Misc/ACKS | 1 + Misc/NEWS | 3 +++ Objects/moduleobject.c | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 3bf81a2..16847be 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 5793aec..0136a44 100644 --- 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. diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index f31b5da..533db46 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -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); -- cgit v0.12