[Python-checkins] cpython (merge 3.2 -> default): Issue #15394: Fix ref leaks in PyModule_Create.
meador.inge
python-checkins at python.org
Thu Jul 19 20:52:43 CEST 2012
http://hg.python.org/cpython/rev/571777bf5527
changeset: 78179:571777bf5527
parent: 78177:9e94eb39aaad
parent: 78178:7140d97d36fd
user: Meador Inge <meadori at gmail.com>
date: Thu Jul 19 13:51:59 2012 -0500
summary:
Issue #15394: Fix ref leaks in PyModule_Create.
Patch by Julia Lawall.
files:
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
Objects/moduleobject.c | 8 +++++++-
3 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -601,6 +601,7 @@
Piers Lauder
Ben Laurie
Simon Law
+Julia Lawall
Chris Lawrence
Brian Leair
Mathieu Leduc-Hamel
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
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 has been fixed.
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -126,8 +126,10 @@
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)) {
@@ -135,16 +137,19 @@
"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);
@@ -155,6 +160,7 @@
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);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list