pgsql: In PLy_function_build_args(), the code loops repeatedly, - Mailing list pgsql-committers

From neilc@postgresql.org (Neil Conway)
Subject pgsql: In PLy_function_build_args(), the code loops repeatedly,
Date
Msg-id 20060110003313.469429DC9D8@postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
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.

Modified Files:
--------------
    pgsql/src/pl/plpython:
        plpython.c (r1.69 -> r1.70)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpython/plpython.c.diff?r1=1.69&r2=1.70)

pgsql-committers by date:

Previous
From: momjian@postgresql.org (Bruce Momjian)
Date:
Subject: pgsql: Done: < * %Allow pooled connections to list all prepared
Next
From: neilc@postgresql.org (Neil Conway)
Date:
Subject: pgsql: In PLy_function_build_args(), the code loops repeatedly,