diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index abe445358d..f1aace2d2a 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -263,7 +263,8 @@ PortalCleanup(Portal portal) saveResourceOwner = CurrentResourceOwner; PG_TRY(); { - CurrentResourceOwner = portal->resowner; + if (portal->resowner) + CurrentResourceOwner = portal->resowner; /* we do not need AfterTriggerEndQuery() here */ ExecutorEnd(queryDesc); FreeQueryDesc(queryDesc); @@ -338,7 +339,8 @@ PersistHoldablePortal(Portal portal) PG_TRY(); { ActivePortal = portal; - CurrentResourceOwner = portal->resowner; + if (portal->resowner) + CurrentResourceOwner = portal->resowner; PortalContext = PortalGetHeapMemory(portal); MemoryContextSwitchTo(PortalContext); diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c index d60dc49c3c..d36458d63f 100644 --- a/src/backend/tcop/pquery.c +++ b/src/backend/tcop/pquery.c @@ -481,7 +481,8 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot) PG_TRY(); { ActivePortal = portal; - CurrentResourceOwner = portal->resowner; + if (portal->resowner) + CurrentResourceOwner = portal->resowner; PortalContext = PortalGetHeapMemory(portal); oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal)); @@ -771,7 +772,8 @@ PortalRun(Portal portal, long count, bool isTopLevel, PG_TRY(); { ActivePortal = portal; - CurrentResourceOwner = portal->resowner; + if (portal->resowner) + CurrentResourceOwner = portal->resowner; PortalContext = PortalGetHeapMemory(portal); MemoryContextSwitchTo(PortalContext); @@ -1380,7 +1382,8 @@ PortalRunFetch(Portal portal, PG_TRY(); { ActivePortal = portal; - CurrentResourceOwner = portal->resowner; + if (portal->resowner) + CurrentResourceOwner = portal->resowner; PortalContext = PortalGetHeapMemory(portal); oldContext = MemoryContextSwitchTo(PortalContext);