Fix three Python reference leaks in PLy_traceback(). This would result
authorNeil Conway <neilc@samurai.com>
Mon, 20 Feb 2006 20:10:41 +0000 (20:10 +0000)
committerNeil Conway <neilc@samurai.com>
Mon, 20 Feb 2006 20:10:41 +0000 (20:10 +0000)
in leaking memory when invoking a PL/Python procedure that raises an
exception. Unfortunately this still leaks memory, but at least the
largest leak has been plugged.

This patch also fixes a reference counting mistake in PLy_modify_tuple()
for 8.0, 8.1 and HEAD: we don't actually own a reference to `platt', so
we shouldn't Py_DECREF() it.

src/pl/plpython/plpython.c

index a82e44512349bb687ec1eabf4b3dd46fde23c9ec..2c450b902a6fc6eb57076c5ba19a609b83942552 100644 (file)
@@ -549,7 +549,6 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata,
        {
                Py_XDECREF(plntup);
                Py_XDECREF(plkeys);
-               Py_XDECREF(platt);
                Py_XDECREF(plval);
                Py_XDECREF(plstr);
 
@@ -1080,7 +1079,7 @@ PLy_procedure_create(FunctionCallInfo fcinfo, Oid tgreloid,
                }
 
                /*
-                * now get information required for input conversion of the procedures
+                * now get information required for input conversion of the procedure's
                 * arguments.
                 */
                proc->nargs = fcinfo->nargs;
@@ -2537,6 +2536,7 @@ PLy_traceback(int *xlevel)
        }
 
        PyErr_NormalizeException(&e, &v, &tb);
+       Py_XDECREF(tb);
 
        eob = PyObject_Str(e);
        if ((v) && ((vob = PyObject_Str(v)) != NULL))
@@ -2555,9 +2555,10 @@ PLy_traceback(int *xlevel)
 
        Py_DECREF(eob);
        Py_XDECREF(vob);
+       Py_XDECREF(v);
 
        /*
-        * intuit an appropriate error level for based on the exception type
+        * intuit an appropriate error level based on the exception type
         */
        if ((PLy_exc_error) && (PyErr_GivenExceptionMatches(e, PLy_exc_error)))
                *xlevel = ERROR;
@@ -2566,6 +2567,7 @@ PLy_traceback(int *xlevel)
        else
                *xlevel = ERROR;
 
+       Py_DECREF(e);
        return xstr;
 }