summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path
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/optimizer/path
parent9f76d0d926ffe72e32248b7c79f585c47e643981 (diff)
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/optimizer/path')
-rw-r--r--src/backend/optimizer/path/pathkeys.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index af0b61a4034..9c6ed4d1bd3 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.42 2002/12/12 15:49:32 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.43 2002/12/17 01:18:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -101,12 +101,17 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
*/
newset = NIL;
- foreach(cursetlink, root->equi_key_list)
+ /* cannot use foreach here because of possible lremove */
+ cursetlink = root->equi_key_list;
+ while (cursetlink)
{
List *curset = lfirst(cursetlink);
bool item1here = member(item1, curset);
bool item2here = member(item2, curset);
+ /* must advance cursetlink before lremove possibly pfree's it */
+ cursetlink = lnext(cursetlink);
+
if (item1here || item2here)
{
/*
@@ -128,9 +133,7 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
newset = set_union(newset, curset);
/*
- * Remove old set from equi_key_list. NOTE this does not
- * change lnext(cursetlink), so the foreach loop doesn't
- * break.
+ * Remove old set from equi_key_list.
*/
root->equi_key_list = lremove(curset, root->equi_key_list);
freeList(curset); /* might as well recycle old cons cells */