Mercurial > vim
diff src/if_py_both.h @ 4831:b8eabb6a9687 v7.3.1162
updated for version 7.3.1162
Problem: Python: Memory leaks
Solution: Add more Py_DECREF(). (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 10 Jun 2013 20:47:36 +0200 |
parents | ff3935926449 |
children | 70b1178dec79 |
line wrap: on
line diff
--- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -5354,6 +5354,7 @@ populate_module(PyObject *m, object_adde { int i; PyObject *other_module; + PyObject *attr; for (i = 0; i < (int)(sizeof(numeric_constants) / sizeof(struct numeric_constant)); @@ -5392,14 +5393,26 @@ populate_module(PyObject *m, object_adde if (!(py_chdir = PyObject_GetAttrString(other_module, "chdir"))) return -1; ADD_OBJECT(m, "_chdir", py_chdir); - if (PyObject_SetAttrString(other_module, "chdir", get_attr(m, "chdir"))) + if (!(attr = get_attr(m, "chdir"))) return -1; + if (PyObject_SetAttrString(other_module, "chdir", attr)) + { + Py_DECREF(attr); + return -1; + } + Py_DECREF(attr); if ((py_fchdir = PyObject_GetAttrString(other_module, "fchdir"))) { ADD_OBJECT(m, "_fchdir", py_fchdir); - if (PyObject_SetAttrString(other_module,"fchdir",get_attr(m,"fchdir"))) + if (!(attr = get_attr(m, "fchdir"))) return -1; + if (PyObject_SetAttrString(other_module, "fchdir", attr)) + { + Py_DECREF(attr); + return -1; + } + Py_DECREF(attr); } else PyErr_Clear();