Commit b2c34e2b authored by Bruce Momjian's avatar Bruce Momjian

I have attached the pltcl patch again, just in case. For the sake of clarity

let's say this patch superscedes the previous one.

I have also attached a patch addressing the similar memory leak problem in
plpython. This includes a slight adjustment of the tests in the source
directory. The patch also includes a cosmetic change to remove a compiler
warning although I think the change makes the code look worse though.

BTW, by my reckoning the memory leak would occur with prepared plans and
without. If that is not the case then I've been barking up the wrong tree.

Nigel J. Andrews
parent 5ad4faf1
...@@ -29,7 +29,7 @@ SELECT global_test_two(); ...@@ -29,7 +29,7 @@ SELECT global_test_two();
(1 row) (1 row)
SELECT import_fail(); SELECT import_fail();
WARNING: ('import socket failed -- untrusted dynamic module: _socket',) NOTICE: ('import socket failed -- untrusted dynamic module: _socket',)
import_fail import_fail
-------------------- --------------------
failed as expected failed as expected
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.22 2002/09/04 22:51:23 petere Exp $ * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.23 2002/09/26 05:23:26 momjian Exp $
* *
********************************************************************* *********************************************************************
*/ */
...@@ -408,7 +408,9 @@ plpython_call_handler(PG_FUNCTION_ARGS) ...@@ -408,7 +408,9 @@ plpython_call_handler(PG_FUNCTION_ARGS)
else else
PLy_restart_in_progress += 1; PLy_restart_in_progress += 1;
if (proc) if (proc)
{
Py_DECREF(proc->me); Py_DECREF(proc->me);
}
RERAISE_EXC(); RERAISE_EXC();
} }
...@@ -1841,7 +1843,14 @@ PLy_plan_dealloc(PyObject * arg) ...@@ -1841,7 +1843,14 @@ PLy_plan_dealloc(PyObject * arg)
* *
* FIXME -- leaks saved plan on object destruction. can this be * FIXME -- leaks saved plan on object destruction. can this be
* avoided? * 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);
} }
if (ob->types) if (ob->types)
PLy_free(ob->types); PLy_free(ob->types);
...@@ -2374,6 +2383,8 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status) ...@@ -2374,6 +2383,8 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
PyList_SetItem(result->rows, i, row); PyList_SetItem(result->rows, i, row);
} }
PLy_typeinfo_dealloc(&args); PLy_typeinfo_dealloc(&args);
SPI_freetuptable(tuptable);
} }
RESTORE_EXC(); RESTORE_EXC();
} }
......
...@@ -20,7 +20,7 @@ CREATE TABLE taxonomy ( ...@@ -20,7 +20,7 @@ CREATE TABLE taxonomy (
CREATE TABLE entry ( CREATE TABLE entry (
accession text not null primary key, accession text not null primary key,
eid serial, eid serial unique,
txid int2 not null references taxonomy(id) txid int2 not null references taxonomy(id)
) ; ) ;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* ENHANCEMENTS, OR MODIFICATIONS. * ENHANCEMENTS, OR MODIFICATIONS.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.62 2002/09/21 18:39:26 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.63 2002/09/26 05:23:26 momjian Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -1647,6 +1647,7 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp, ...@@ -1647,6 +1647,7 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp,
pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc); pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc);
sprintf(buf, "%d", ntuples); sprintf(buf, "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE); Tcl_SetResult(interp, buf, TCL_VOLATILE);
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_OK; return TCL_OK;
} }
...@@ -1668,15 +1669,19 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp, ...@@ -1668,15 +1669,19 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp,
continue; continue;
if (loop_rc == TCL_RETURN) if (loop_rc == TCL_RETURN)
{ {
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_RETURN; return TCL_RETURN;
} }
if (loop_rc == TCL_BREAK) if (loop_rc == TCL_BREAK)
break; break;
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_ERROR; return TCL_ERROR;
} }
SPI_freetuptable(SPI_tuptable);
/************************************************************ /************************************************************
* Finally return the number of tuples * Finally return the number of tuples
************************************************************/ ************************************************************/
...@@ -2207,6 +2212,7 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp, ...@@ -2207,6 +2212,7 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
{ {
if (ntuples > 0) if (ntuples > 0)
pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc); pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc);
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
sprintf(buf, "%d", ntuples); sprintf(buf, "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE); Tcl_SetResult(interp, buf, TCL_VOLATILE);
...@@ -2229,15 +2235,19 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp, ...@@ -2229,15 +2235,19 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
continue; continue;
if (loop_rc == TCL_RETURN) if (loop_rc == TCL_RETURN)
{ {
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_RETURN; return TCL_RETURN;
} }
if (loop_rc == TCL_BREAK) if (loop_rc == TCL_BREAK)
break; break;
SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_ERROR; return TCL_ERROR;
} }
SPI_freetuptable(SPI_tuptable);
/************************************************************ /************************************************************
* Finally return the number of tuples * Finally return the number of tuples
************************************************************/ ************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment