Re: BUG #2817: Mixing spi_prepare and spi_exec_query causes postgresql to terminate itself on bad argument types - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #2817: Mixing spi_prepare and spi_exec_query causes postgresql to terminate itself on bad argument types
Date
Msg-id 23182.1165538532@sss.pgh.pa.us
Whole thread Raw
In response to BUG #2817: Mixing spi_prepare and spi_exec_query causes postgresql to terminate itself on bad argument types  ("Michael Andreen" <harv@ruin.nu>)
List pgsql-bugs
"Michael Andreen" <harv@ruin.nu> writes:
> CREATE OR REPLACE FUNCTION crash()
>   RETURNS int4 AS
> $BODY$$rv = spi_exec_query("SELECT 1");
> $query = spi_prepare('SELECT 1 WHERE 1 = $1','integer');
> return 1;$BODY$
>   LANGUAGE 'plperl' VOLATILE;

Thanks for the test case.  This is not plperl's fault, it's the
consequence of some anti-memory-leak code added very recently.
Here's the fix if you need it right away...

            regards, tom lane


*** src/backend/executor/spi.c.orig    Tue Nov 21 17:35:29 2006
--- src/backend/executor/spi.c    Thu Dec  7 19:33:33 2006
***************
*** 1543,1548 ****
--- 1543,1551 ----
      SPI_lastoid = my_lastoid;
      SPI_tuptable = my_tuptable;

+     /* tuptable now is caller's responsibility, not SPI's */
+     _SPI_current->tuptable = NULL;
+
      return my_res;
  }

***************
*** 1694,1699 ****
--- 1697,1705 ----
      /* Put the result into place for access by caller */
      SPI_processed = _SPI_current->processed;
      SPI_tuptable = _SPI_current->tuptable;
+
+     /* tuptable now is caller's responsibility, not SPI's */
+     _SPI_current->tuptable = NULL;

      /* Pop the SPI stack */
      _SPI_end_call(true);

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #2811: Error determining param type in prepared statement of unused variable
Next
From: Juan Pablo Yañez
Date:
Subject: unsubscribe