From cdd3fcde53209e698ebe7a6e88a7cdbaf56d46ba Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 8 Jul 2009 11:06:03 +0100 Subject: [PATCH] Fix reference leaks. --- pybindgen/pytypeobject.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pybindgen/pytypeobject.py b/pybindgen/pytypeobject.py index eb3b816..4ab4080 100644 --- a/pybindgen/pytypeobject.py +++ b/pybindgen/pytypeobject.py @@ -236,8 +236,11 @@ static Py_ssize_t Py_ssize_t result; py_result = %(method_name)s(py_self); + if (py_result == NULL) { + return -1; + } result = PyInt_AsSsize_t(py_result); - + Py_DECREF(py_result); return result; } @@ -249,13 +252,12 @@ static PyObject* { PyObject *result; PyObject *args; - PyObject *kwargs; args = Py_BuildValue("(i)", py_i); - kwargs = Py_BuildValue("{}"); - result = %(method_name)s(py_self, args, kwargs); + result = %(method_name)s(py_self, args, NULL); if (PyErr_ExceptionMatches(PyExc_IndexError) || PyErr_ExceptionMatches(PyExc_StopIteration)) { + Py_XDECREF(result); return NULL; } else { return result; @@ -271,14 +273,14 @@ static int { PyObject *result; PyObject *args; - PyObject *kwargs; args = Py_BuildValue("(iO)", py_i, py_val); - kwargs = Py_BuildValue("{}"); - result = %(method_name)s(py_self, args, kwargs); + result = %(method_name)s(py_self, args, NULL); + Py_DECREF(args); if (result == NULL) { return -1; } else { + Py_DECREF(result); return 0; } }