* procedural language
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.64 2002/09/05 00:43:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.65 2002/10/19 22:10:58 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
expr->plan_simple_expr = NULL;
exec_simple_check_plan(expr);
+ SPI_freeplan(plan);
pfree(argtypes);
}
* ----------
*/
curplan = SPI_prepare(querystr, 0, NULL);
+ if (curplan == NULL)
+ elog(ERROR, "SPI_prepare() failed for dynamic query \"%s\"",
+ querystr);
portal = SPI_cursor_open(curname, curplan, NULL, NULL);
if (portal == NULL)
elog(ERROR, "Failed to open cursor");
pfree(querystr);
+ SPI_freeplan(curplan);
/* ----------
* Store the eventually assigned cursor name in the cursor variable
* 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 $
*
*********************************************************************
*/
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)
PyObject *list = NULL;
PyObject *volatile optr = NULL;
char *query;
+ void *tmpplan;
enter();
int nargs,
i;
-
nargs = PySequence_Length(list);
if (nargs > 0)
{
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,
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.65 2002/10/14 04:20:52 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.66 2002/10/19 22:10:58 tgl Exp $
*
**********************************************************************/
else if (strcmp(argv[1], "NOTICE") == 0)
level = NOTICE;
else if (strcmp(argv[1], "WARNING") == 0)
- level = ERROR;
+ level = WARNING;
else if (strcmp(argv[1], "ERROR") == 0)
level = ERROR;
else if (strcmp(argv[1], "FATAL") == 0)
}
/************************************************************
- * Save the plan
+ * Save the plan into permanent memory (right now it's in the
+ * SPI procCxt, which will go away at function end).
************************************************************/
qdesc->plan = SPI_saveplan(plan);
if (qdesc->plan == NULL)
elog(ERROR, "pltcl: SPI_saveplan() failed - %s", reason);
}
+ /* Release the procCxt copy to avoid within-function memory leak */
+ SPI_freeplan(plan);
/************************************************************
* Insert a hashtable entry for the plan and return