summaryrefslogtreecommitdiffstats
path: root/Objects/moduleobject.c
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2012-07-19 18:51:59 (GMT)
committerMeador Inge <meadori@gmail.com>2012-07-19 18:51:59 (GMT)
commitf4cc2161d567460f27a1390277ba6c70581ebc0d (patch)
treef7fd69613b99aee65f5831d5fca30f6ca7010c1a /Objects/moduleobject.c
parent77d32833700f6ffc05b04e3838bb52e0bb39e2a9 (diff)
parent29e49d63942cc75ead85a4cb77dea34285be9fcc (diff)
downloadcpython-f4cc2161d567460f27a1390277ba6c70581ebc0d.zip
cpython-f4cc2161d567460f27a1390277ba6c70581ebc0d.tar.gz
cpython-f4cc2161d567460f27a1390277ba6c70581ebc0d.tar.bz2
Issue #15394: Fix ref leaks in PyModule_Create.
Patch by Julia Lawall.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r--Objects/moduleobject.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index d50b2b2..2f2bd36 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -126,8 +126,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)) {
@@ -135,16 +137,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);
@@ -155,6 +160,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);