Kaydet (Commit) f4cc2161 authored tarafından Meador Inge's avatar Meador Inge

Issue #15394: Fix ref leaks in PyModule_Create.

Patch by Julia Lawall.
......@@ -601,6 +601,7 @@ Amos Latteier
Piers Lauder
Ben Laurie
Simon Law
Julia Lawall
Chris Lawrence
Brian Leair
Mathieu Leduc-Hamel
......
......@@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 2?
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.
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment