Re: PLTCL return_null crash... - Mailing list pgsql-general

From Tom Lane
Subject Re: PLTCL return_null crash...
Date
Msg-id 1375.1034084364@sss.pgh.pa.us
Whole thread Raw
In response to Re: PLTCL return_null crash...  (Joe Conway <mail@joeconway.com>)
List pgsql-general
Joe Conway <mail@joeconway.com> writes:
> Any idea wht I can't step through this? In any case, the problem seems to be
> in this section of code:

> <snip>
> if (SPI_finish() != SPI_OK_FINISH)
>    elog(ERROR, "pltcl: SPI_finish() failed");

> UTF_BEGIN;
> if (fcinfo->isnull)
>    retval = (Datum) 0;
> else
>    retval = FunctionCall3(&prodesc->result_in_func,
>                           PointerGetDatum(UTF_U2E(interp->result)),
>                           ObjectIdGetDatum(prodesc->result_in_elem),
>                           Int32GetDatum(-1));
> UTF_END;
> </snip>

Oh, but of course: if you are returning NULL then this sequence fails
because it pfrees an uninitialized pointer.  It's fixed in CVS tip,
where the sequence reads like

    if (SPI_finish() != SPI_OK_FINISH)
        elog(ERROR, "pltcl: SPI_finish() failed");

    if (fcinfo->isnull)
        retval = (Datum) 0;
    else
    {
        UTF_BEGIN;
        retval = FunctionCall3(&prodesc->result_in_func,
                               PointerGetDatum(UTF_U2E(interp->result)),
                               ObjectIdGetDatum(prodesc->result_in_elem),
                               Int32GetDatum(-1));
        UTF_END;
    }

The reason I failed to duplicate it here was I didn't compile with
--enable-multibyte.  The bug is definitely still there in 7.2.3 if
you use multibyte.

            regards, tom lane

pgsql-general by date:

Previous
From: Elielson Fontanezi
Date:
Subject: pg_dump command inside shell scripts
Next
From: Tom Lane
Date:
Subject: Re: Server locale?