summaryrefslogtreecommitdiff
path: root/numpy/f2py/rules.py
diff options
context:
space:
mode:
authorSergei Lebedev <slebedev@google.com>2019-08-07 11:07:15 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2019-08-19 11:03:59 -0500
commit4ada0641ed1a50a2473f8061f4808b4b0d68eff5 (patch)
tree1a09d526baa152b6766b0252cbf2d7e5d1cdda00 /numpy/f2py/rules.py
parente2b5f60e6881a57f53bb6051b4555917d1e05fa7 (diff)
downloadnumpy-4ada0641ed1a50a2473f8061f4808b4b0d68eff5.tar.gz
BUG: Fix leak in the f2py-generated module init and `PyMem_Del` usage
Using `PyMem_Del` is incorrect, it should be `PyObject_Del` here, while this worked most of the time, it would lead to crashes at least on python 2.5 (after the reference counts were fixed)
Diffstat (limited to 'numpy/f2py/rules.py')
-rwxr-xr-x[-rw-r--r--]numpy/f2py/rules.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index 6769f1b1f..1b41498ea 100644..100755
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -202,7 +202,7 @@ PyMODINIT_FUNC PyInit_#modulename#(void) {
PyMODINIT_FUNC init#modulename#(void) {
#endif
\tint i;
-\tPyObject *m,*d, *s;
+\tPyObject *m,*d, *s, *tmp;
#if PY_VERSION_HEX >= 0x03000000
\tm = #modulename#_module = PyModule_Create(&moduledef);
#else
@@ -224,8 +224,11 @@ PyMODINIT_FUNC init#modulename#(void) {
\tPyDict_SetItemString(d, \"__doc__\", s);
\t#modulename#_error = PyErr_NewException (\"#modulename#.error\", NULL, NULL);
\tPy_DECREF(s);
-\tfor(i=0;f2py_routine_defs[i].name!=NULL;i++)
-\t\tPyDict_SetItemString(d, f2py_routine_defs[i].name,PyFortranObject_NewAsAttr(&f2py_routine_defs[i]));
+\tfor(i=0;f2py_routine_defs[i].name!=NULL;i++) {
+\t\ttmp = PyFortranObject_NewAsAttr(&f2py_routine_defs[i]);
+\t\tPyDict_SetItemString(d, f2py_routine_defs[i].name, tmp);
+\t\tPy_DECREF(tmp);
+\t}
#initf2pywraphooks#
#initf90modhooks#
#initcommonhooks#