1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-11 00:12:06 +03:00

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.
This commit is contained in:
Tom Lane
2002-12-17 01:18:35 +00:00
parent 9f76d0d926
commit e932a724a4
6 changed files with 51 additions and 32 deletions

View File

@@ -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 */

View File

@@ -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);
}