From 0d54d6ac44444c05f7c0f5058d3d3f32cc188b48 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Jan 2001 00:39:20 +0000 Subject: Clean up handling of tuple descriptors so that result-tuple descriptors allocated by plan nodes are not leaked at end of query. This doesn't really matter for normal queries, but it sure does for queries invoked repetitively inside SQL functions. Clean up some other grotty code associated with tupdescs, and fix a few other memory leaks exposed by tests with simple SQL functions. --- src/backend/commands/command.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/backend/commands/command.c') diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 618322645f3..30695a7a90b 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.119 2001/01/24 19:42:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.120 2001/01/29 00:39:20 tgl Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -1102,7 +1102,7 @@ AlterTableAddConstraint(char *relationName, bool successful = true; HeapScanDesc scan; ExprContext *econtext; - TupleTableSlot *slot = makeNode(TupleTableSlot); + TupleTableSlot *slot; HeapTuple tuple; RangeTblEntry *rte; List *qual; @@ -1169,28 +1169,28 @@ AlterTableAddConstraint(char *relationName, qual = makeList1(expr); + /* Make tuple slot to hold tuples */ + slot = MakeTupleTableSlot(); + ExecSetSlotDescriptor(slot, RelationGetDescr(rel), false); + /* Make an expression context for ExecQual */ + econtext = MakeExprContext(slot, CurrentMemoryContext); + /* - * Scan through the rows now, making the necessary things - * for ExecQual, and then call it to evaluate the - * expression. + * Scan through the rows now, checking the expression + * at each row. */ while (HeapTupleIsValid(tuple = heap_getnext(scan, 0))) { - slot->val = tuple; - slot->ttc_shouldFree = false; - slot->ttc_descIsNew = true; - slot->ttc_tupleDescriptor = rel->rd_att; - slot->ttc_buffer = InvalidBuffer; - - econtext = MakeExprContext(slot, CurrentMemoryContext); + ExecStoreTuple(tuple, slot, InvalidBuffer, false); if (!ExecQual(qual, econtext, true)) { successful=false; break; } - FreeExprContext(econtext); + ResetExprContext(econtext); } + FreeExprContext(econtext); pfree(slot); heap_endscan(scan); -- cgit v1.2.3