Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit629b3e9

Browse files
committed
Only install a portal's ResourceOwner if it actually has one.
In most scenarios a portal without a ResourceOwner is dead and not subjectto any further execution, but a portal for a cursor WITH HOLD remains inexistence with no ResourceOwner after the creating transaction is over.In this situation, if we attempt to "execute" the portal directly to fetchdata from it, we were setting CurrentResourceOwner to NULL, leading to asegfault if the datatype output code did anything that required a resourceowner (such as trying to fetch system catalog entries that weren't alreadycached). The case appears to be impossible to provoke with stock libpq,but psqlODBC at least is able to cause it when working with held cursors.Simplest fix is to just skip the assignment to CurrentResourceOwner, sothat any resources used by the data output operations will be managed bythe transaction-level resource owner instead. For consistency I changedall the places that install a portal's resowner as current, even thoughsome of them are probably not reachable with a held cursor's portal.Per report from Joshua Berry (with thanks to Hiroshi Inoue for developinga self-contained test case). Back-patch to all supported versions.
1 parent6600856 commit629b3e9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

‎src/backend/commands/portalcmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ PortalCleanup(Portal portal)
274274
saveResourceOwner=CurrentResourceOwner;
275275
PG_TRY();
276276
{
277-
CurrentResourceOwner=portal->resowner;
277+
if (portal->resowner)
278+
CurrentResourceOwner=portal->resowner;
278279
ExecutorFinish(queryDesc);
279280
ExecutorEnd(queryDesc);
280281
FreeQueryDesc(queryDesc);
@@ -349,7 +350,8 @@ PersistHoldablePortal(Portal portal)
349350
PG_TRY();
350351
{
351352
ActivePortal=portal;
352-
CurrentResourceOwner=portal->resowner;
353+
if (portal->resowner)
354+
CurrentResourceOwner=portal->resowner;
353355
PortalContext=PortalGetHeapMemory(portal);
354356

355357
MemoryContextSwitchTo(PortalContext);

‎src/backend/tcop/pquery.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ PortalStart(Portal portal, ParamListInfo params,
478478
PG_TRY();
479479
{
480480
ActivePortal=portal;
481-
CurrentResourceOwner=portal->resowner;
481+
if (portal->resowner)
482+
CurrentResourceOwner=portal->resowner;
482483
PortalContext=PortalGetHeapMemory(portal);
483484

484485
oldContext=MemoryContextSwitchTo(PortalGetHeapMemory(portal));
@@ -762,7 +763,8 @@ PortalRun(Portal portal, long count, bool isTopLevel,
762763
PG_TRY();
763764
{
764765
ActivePortal=portal;
765-
CurrentResourceOwner=portal->resowner;
766+
if (portal->resowner)
767+
CurrentResourceOwner=portal->resowner;
766768
PortalContext=PortalGetHeapMemory(portal);
767769

768770
MemoryContextSwitchTo(PortalContext);
@@ -1411,7 +1413,8 @@ PortalRunFetch(Portal portal,
14111413
PG_TRY();
14121414
{
14131415
ActivePortal=portal;
1414-
CurrentResourceOwner=portal->resowner;
1416+
if (portal->resowner)
1417+
CurrentResourceOwner=portal->resowner;
14151418
PortalContext=PortalGetHeapMemory(portal);
14161419

14171420
oldContext=MemoryContextSwitchTo(PortalContext);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp