aboutsummaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpython.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-10-19 22:10:58 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-10-19 22:10:58 +0000
commit4a67565b37ef4fae12c341d069b1145cfae10144 (patch)
tree63755e34ce59feddff4a9fbeafb0c3d716b9c58f /src/pl/plpython/plpython.c
parent30c2b5ec7212c7b6881a7a25ca604ffe5229059d (diff)
downloadpostgresql-4a67565b37ef4fae12c341d069b1145cfae10144.tar.gz
postgresql-4a67565b37ef4fae12c341d069b1145cfae10144.zip
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.
Diffstat (limited to 'src/pl/plpython/plpython.c')
-rw-r--r--src/pl/plpython/plpython.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 005d85e9ce1..43c34271961 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -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,