Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 87081b2

Browse files
committed
Fix an oversight in my patch of a couple weeks ago that ensured a snapshot
is available during datatype input in Bind message processing. I put the PopActiveSnapshot() or equivalent just before PortalDefineQuery, which is an unsafe spot for it (in 8.3 and later) because we are carrying a plancache refcount that hasn't yet been assigned to the portal. Any error thrown there would result in leaking the refcount. It's not exactly likely that PopActiveSnapshot would throw an elog, perhaps, but it could happen. Reorder the code and add another comment warning not to do that.
1 parent df0ea5a commit 87081b2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/backend/tcop/postgres.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.562 2008/12/13 02:29:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.563 2009/01/01 17:12:16 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1714,12 +1714,11 @@ exec_bind_message(StringInfo input_message)
17141714
cplan = NULL;
17151715
}
17161716

1717-
/* Done with the snapshot used for parameter I/O and parsing/planning */
1718-
if (snapshot_set)
1719-
PopActiveSnapshot();
1720-
17211717
/*
1722-
* Define portal and start execution.
1718+
* Now we can define the portal.
1719+
*
1720+
* DO NOT put any code that could possibly throw an error between the
1721+
* above "RevalidateCachedPlan(psrc, false)" call and here.
17231722
*/
17241723
PortalDefineQuery(portal,
17251724
saved_stmt_name,
@@ -1728,6 +1727,13 @@ exec_bind_message(StringInfo input_message)
17281727
plan_list,
17291728
cplan);
17301729

1730+
/* Done with the snapshot used for parameter I/O and parsing/planning */
1731+
if (snapshot_set)
1732+
PopActiveSnapshot();
1733+
1734+
/*
1735+
* And we're ready to start portal execution.
1736+
*/
17311737
PortalStart(portal, params, InvalidSnapshot);
17321738

17331739
/*

0 commit comments

Comments
 (0)