diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-17 01:18:35 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-17 01:18:35 +0000 |
| commit | e932a724a4a372c7db21ce7bf40250576b085041 (patch) | |
| tree | 02e45ca5656b4838336b1b2b6e9e31cea2f721dc /src/backend/optimizer/plan/initsplan.c | |
| parent | 9f76d0d926ffe72e32248b7c79f585c47e643981 (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/plan/initsplan.c')
| -rw-r--r-- | src/backend/optimizer/plan/initsplan.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index aca2c6f4f67..151a37a8889 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.78 2002/12/12 15:49:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.79 2002/12/17 01:18:25 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -910,13 +910,18 @@ qual_is_redundant(Query *root, do { someadded = false; - foreach(olditem, oldquals) + /* cannot use foreach here because of possible lremove */ + olditem = oldquals; + while (olditem) { RestrictInfo *oldrinfo = (RestrictInfo *) lfirst(olditem); Node *oldleft = (Node *) get_leftop(oldrinfo->clause); Node *oldright = (Node *) get_rightop(oldrinfo->clause); Node *newguy = NULL; + /* must advance olditem before lremove possibly pfree's it */ + olditem = lnext(olditem); + if (member(oldleft, equalvars)) newguy = oldright; else if (member(oldright, equalvars)) @@ -930,8 +935,6 @@ qual_is_redundant(Query *root, /* * Remove this qual from list, since we don't need it anymore. - * Note this doesn't break the foreach() loop, since lremove - * doesn't touch the next-link of the removed cons cell. */ oldquals = lremove(oldrinfo, oldquals); } |
