Commit 376c6203 authored by Tom Lane's avatar Tom Lane

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.
parent 04ef4040
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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) ...@@ -328,6 +328,13 @@ PortalReleaseCachedPlan(Portal portal)
{ {
ReleaseCachedPlan(portal->cplan, false); ReleaseCachedPlan(portal->cplan, false);
portal->cplan = NULL; 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) ...@@ -395,8 +402,7 @@ PortalDrop(Portal portal, bool isTopCommit)
(*portal->cleanup) (portal); (*portal->cleanup) (portal);
/* drop cached plan reference, if any */ /* drop cached plan reference, if any */
if (portal->cplan) PortalReleaseCachedPlan(portal);
PortalReleaseCachedPlan(portal);
/* /*
* Release any resources still attached to the portal. There are several * Release any resources still attached to the portal. There are several
...@@ -529,8 +535,7 @@ CommitHoldablePortals(void) ...@@ -529,8 +535,7 @@ CommitHoldablePortals(void)
PersistHoldablePortal(portal); PersistHoldablePortal(portal);
/* drop cached plan reference, if any */ /* drop cached plan reference, if any */
if (portal->cplan) PortalReleaseCachedPlan(portal);
PortalReleaseCachedPlan(portal);
/* /*
* Any resources belonging to the portal will be released in the * Any resources belonging to the portal will be released in the
...@@ -680,8 +685,7 @@ AtAbort_Portals(void) ...@@ -680,8 +685,7 @@ AtAbort_Portals(void)
} }
/* drop cached plan reference, if any */ /* drop cached plan reference, if any */
if (portal->cplan) PortalReleaseCachedPlan(portal);
PortalReleaseCachedPlan(portal);
/* /*
* Any resources belonging to the portal will be released in the * Any resources belonging to the portal will be released in the
...@@ -823,8 +827,7 @@ AtSubAbort_Portals(SubTransactionId mySubid, ...@@ -823,8 +827,7 @@ AtSubAbort_Portals(SubTransactionId mySubid,
} }
/* drop cached plan reference, if any */ /* drop cached plan reference, if any */
if (portal->cplan) PortalReleaseCachedPlan(portal);
PortalReleaseCachedPlan(portal);
/* /*
* Any resources belonging to the portal will be released in the * Any resources belonging to the portal will be released in the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment