Oops, in the previous fix to prevent a cursor that's being used in a FOR
authorHeikki Linnakangas <[email protected]>
Tue, 13 Jul 2010 09:03:01 +0000 (09:03 +0000)
committerHeikki Linnakangas <[email protected]>
Tue, 13 Jul 2010 09:03:01 +0000 (09:03 +0000)
loop from being dropped, I missed subtransaction cleanup. Pinned portals
must be dropped at subtransaction cleanup just as they are at main
transaction cleanup.

Per bug #5556 by Robert Walker. Backpatch to 8.0, 7.4 didn't have
subtransactions.

src/backend/utils/mmgr/portalmem.c

index 303c98e6286f84964e8b328cec3f66e138c96a19..bc668364ff35dea62d021563b0eb5e32ff57ba4a 100644 (file)
@@ -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.82.2.3 2010/07/05 09:27:42 heikki Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.82.2.4 2010/07/13 09:03:01 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -294,6 +294,9 @@ PortalCreateHoldStore(Portal portal)
 /*
  * PinPortal
  *     Protect a portal from dropping.
+ *
+ * A pinned portal is still unpinned and dropped at transaction or
+ * subtransaction abort.
  */
 void
 PinPortal(Portal portal)
@@ -798,6 +801,14 @@ AtSubCleanup_Portals(SubTransactionId mySubid)
        if (portal->createSubid != mySubid)
            continue;
 
+       /*
+        * If a portal is still pinned, forcibly unpin it. PortalDrop will not
+        * let us drop the portal otherwise. Whoever pinned the portal was
+        * interrupted by the abort too and won't try to use it anymore.
+        */
+       if (portal->portalPinned)
+           portal->portalPinned = false;
+
        /* Zap it. */
        PortalDrop(portal, false);
    }