1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Fix within-function memory leaks in the various PLs' interfaces to

SPI_prepare: they all save the prepared plan into topCxt, and so the
procCxt copy that's actually returned by SPI_prepare ought to be freed.
Diagnosis and plpython fix by Nigel Andrews, followup for other PLs
by Tom Lane.
This commit is contained in:
Tom Lane
2002-10-19 22:10:58 +00:00
parent 30c2b5ec72
commit 4a67565b37
3 changed files with 19 additions and 22 deletions

View File

@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.25 2002/10/14 04:20:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.26 2002/10/19 22:10:58 tgl Exp $
*
*********************************************************************
*/
@ -1837,21 +1837,7 @@ PLy_plan_dealloc(PyObject * arg)
enter();
if (ob->plan)
{
/*
* free the plan... pfree(ob->plan);
*
* FIXME -- leaks saved plan on object destruction. can this be
* avoided?
* I think so. A function prepares and then execp's a statement.
* When we come to deallocate the 'statement' object we obviously
* no long need the plan. Even if we did, without the object
* we're never going to be able to use it again.
* In the against arguments: SPI_saveplan has stuck this under
* the top context so there must be a reason for doing that.
*/
pfree(ob->plan);
}
SPI_freeplan(ob->plan);
if (ob->types)
PLy_free(ob->types);
if (ob->args)
@ -2023,6 +2009,7 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
PyObject *list = NULL;
PyObject *volatile optr = NULL;
char *query;
void *tmpplan;
enter();
@ -2062,7 +2049,6 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
int nargs,
i;
nargs = PySequence_Length(list);
if (nargs > 0)
{
@ -2125,7 +2111,10 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
RAISE_EXC(1);
}
plan->plan = SPI_saveplan(plan->plan);
/* transfer plan from procCxt to topCxt */
tmpplan = plan->plan;
plan->plan = SPI_saveplan(tmpplan);
SPI_freeplan(tmpplan);
if (plan->plan == NULL)
{
PLy_exception_set(PLy_exc_spi_error,