postgres.git / summary / log / commit / refs

commit    c08c8529e707ded90f5b3366a9c17fa7d435e978
Author:   Neil Conway <neilc@samurai.com>
Date:     Tue Jan 10 00:33:12 2006 +0000
First released in: 8.2.0, 8.0.7, 8.1.3

    In PLy_function_build_args(), the code loops repeatedly, constructing
    one argument at a time and then inserting the argument into a Python
    list via PyList_SetItem(). This "steals" the reference to the argument:
    that is, the reference to the new list member is now held by the Python
    list itself. This works fine, except if an elog occurs. This causes the
    function's PG_CATCH() block to be invoked, which decrements the
    reference counts on both the current argument and the list of arguments.
    If the elog happens to occur during the second or subsequent iteration
    of the loop, the reference count on the current argument will be
    decremented twice.
    
    The fix is simple: set the local pointer to the current argument to NULL
    immediately after adding it to the argument list. This ensures that the
    Py_XDECREF() in the PG_CATCH() block doesn't double-decrement.


src/pl/plpython/plpython.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index 39acb47e69b..2632e93493b 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -29,7 +29,7 @@ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.69 2006/01/09 02:47:09 neilc Exp $ + * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.70 2006/01/10 00:33:12 neilc Exp $ * ********************************************************************* */ @@ -895,6 +895,7 @@ PLy_function_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc) * FIXME -- error check this */ PyList_SetItem(args, i, arg); + arg = NULL; } } PG_CATCH(); [parent: 42ff6a04d85a]