aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-01-18 02:30:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-01-18 02:30:25 +0000
commit376c6203cccd6251ffa83c98ce75f2a06cd95043 (patch)
treefa40fecef1deed368fd94d187172427f0aa5e7bf /src
parent04ef4040186ac08b78ef0c88b78df3b0af4d6346 (diff)
downloadpostgresql-376c6203cccd6251ffa83c98ce75f2a06cd95043.tar.gz
postgresql-376c6203cccd6251ffa83c98ce75f2a06cd95043.zip
Fix portalmem.c to avoid keeping a dangling pointer to a cached plan list
after it's released its reference count for the cached plan. There are code paths that might try to examine the plan list before noticing that the portal is already in aborted state. Report and diagnosis by Tatsuo Ishii, though this isn't exactly his proposed patch.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/mmgr/portalmem.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index b518b1b8c71..889d4653e14 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.115 2010/01/02 16:57:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.116 2010/01/18 02:30:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -328,6 +328,13 @@ PortalReleaseCachedPlan(Portal portal)
{
ReleaseCachedPlan(portal->cplan, false);
portal->cplan = NULL;
+
+ /*
+ * We must also clear portal->stmts which is now a dangling
+ * reference to the cached plan's plan list. This protects any
+ * code that might try to examine the Portal later.
+ */
+ portal->stmts = NIL;
}
}
@@ -395,8 +402,7 @@ PortalDrop(Portal portal, bool isTopCommit)
(*portal->cleanup) (portal);
/* drop cached plan reference, if any */
- if (portal->cplan)
- PortalReleaseCachedPlan(portal);
+ PortalReleaseCachedPlan(portal);
/*
* Release any resources still attached to the portal. There are several
@@ -529,8 +535,7 @@ CommitHoldablePortals(void)
PersistHoldablePortal(portal);
/* drop cached plan reference, if any */
- if (portal->cplan)
- PortalReleaseCachedPlan(portal);
+ PortalReleaseCachedPlan(portal);
/*
* Any resources belonging to the portal will be released in the
@@ -680,8 +685,7 @@ AtAbort_Portals(void)
}
/* drop cached plan reference, if any */
- if (portal->cplan)
- PortalReleaseCachedPlan(portal);
+ PortalReleaseCachedPlan(portal);
/*
* Any resources belonging to the portal will be released in the
@@ -823,8 +827,7 @@ AtSubAbort_Portals(SubTransactionId mySubid,
}
/* drop cached plan reference, if any */
- if (portal->cplan)
- PortalReleaseCachedPlan(portal);
+ PortalReleaseCachedPlan(portal);
/*
* Any resources belonging to the portal will be released in the