From 55bb309bab10e9e600fe82f6f3924c6870796d16 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 6 Feb 2007 22:49:48 +0000 Subject: [PATCH] Fix an error in the original coding of holdable cursors: PersistHoldablePortal thought that it didn't have to reposition the underlying tuplestore if the portal is atEnd. But this is not so, because tuplestores have separate read and write cursors ... and the read cursor hasn't moved from the start. This mistake explains bug #2970 from William Zhang. Note: the coding here is pretty inefficient, but given that no one has noticed this bug until now, I'd say hardly anyone uses the case where the cursor has been advanced before being persisted. So maybe it's not worth worrying about. --- src/backend/commands/portalcmds.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index be5ca11059..c5d453807e 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -363,7 +363,20 @@ PersistHoldablePortal(Portal portal) */ MemoryContextSwitchTo(portal->holdContext); - if (!portal->atEnd) + if (portal->atEnd) + { + /* we can handle this case even if posOverflow */ + HeapTuple tup; + bool should_free; + + while ((tup = tuplestore_gettuple(portal->holdStore, true, + &should_free)) != NULL) + { + if (should_free) + pfree(tup); + } + } + else { long store_pos; -- 2.39.5