Commit 289898cd authored by Fred Drake's avatar Fred Drake

Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,

the object being inserted was not being DECREFed.

This closes SF bug #444486.
parent 53765753
...@@ -60,14 +60,18 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc, ...@@ -60,14 +60,18 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc,
v = PyCFunction_New(ml, passthrough); v = PyCFunction_New(ml, passthrough);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
Py_DECREF(v);
return NULL; return NULL;
}
Py_DECREF(v); Py_DECREF(v);
} }
if (doc != NULL) { if (doc != NULL) {
v = PyString_FromString(doc); v = PyString_FromString(doc);
if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
Py_DECREF(v);
return NULL; return NULL;
}
Py_DECREF(v); Py_DECREF(v);
} }
return m; return m;
......
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