aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-12-17 01:18:35 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-12-17 01:18:35 +0000
commite932a724a4a372c7db21ce7bf40250576b085041 (patch)
tree02e45ca5656b4838336b1b2b6e9e31cea2f721dc /src/backend/utils/adt/selfuncs.c
parent9f76d0d926ffe72e32248b7c79f585c47e643981 (diff)
downloadpostgresql-e932a724a4a372c7db21ce7bf40250576b085041.tar.gz
postgresql-e932a724a4a372c7db21ce7bf40250576b085041.zip
To suppress memory leakage in long-lived Lists, lremove() should pfree
the cons cell it's deleting from the list. Do this, and fix a few callers that were bogusly assuming it wouldn't free the cons cell.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index c378f8b50e3..58c63c210cc 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.123 2002/12/12 15:49:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.124 2002/12/17 01:18:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1953,10 +1953,15 @@ estimate_num_groups(Query *root, List *groupClauses, double input_rows)
if (HeapTupleIsValid(statsTuple))
ReleaseSysCache(statsTuple);
- foreach(l2, varinfos)
+ /* cannot use foreach here because of possible lremove */
+ l2 = varinfos;
+ while (l2)
{
MyVarInfo *varinfo = (MyVarInfo *) lfirst(l2);
+ /* must advance l2 before lremove possibly pfree's it */
+ l2 = lnext(l2);
+
if (var->varno != varinfo->var->varno &&
vars_known_equal(root, var, varinfo->var))
{
@@ -1969,10 +1974,7 @@ estimate_num_groups(Query *root, List *groupClauses, double input_rows)
}
else
{
- /*
- * Delete the older item. We assume lremove() will not
- * break the lnext link of the item...
- */
+ /* Delete the older item */
varinfos = lremove(varinfo, varinfos);
}
}