From b33f78df17c32364d51f6e5128f8d81d7d3013a2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 21 Aug 2011 18:15:55 -0400 Subject: Fix trigger WHEN conditions when both BEFORE and AFTER triggers exist. Due to tuple-slot mismanagement, evaluation of WHEN conditions for AFTER ROW UPDATE triggers could crash if there had been a BEFORE ROW trigger fired for the same update. Fix by not trying to overload the use of estate->es_trig_tuple_slot. Per report from Yoran Heling. Back-patch to 9.0, when trigger WHEN conditions were introduced. --- src/backend/commands/trigger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backend/commands/trigger.c') diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 4c31f19af95..680962aa444 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -2770,13 +2770,13 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo, } if (HeapTupleIsValid(newtup)) { - if (estate->es_trig_tuple_slot == NULL) + if (estate->es_trig_newtup_slot == NULL) { oldContext = MemoryContextSwitchTo(estate->es_query_cxt); - estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate); + estate->es_trig_newtup_slot = ExecInitExtraTupleSlot(estate); MemoryContextSwitchTo(oldContext); } - newslot = estate->es_trig_tuple_slot; + newslot = estate->es_trig_newtup_slot; if (newslot->tts_tupleDescriptor != tupdesc) ExecSetSlotDescriptor(newslot, tupdesc); ExecStoreTuple(newtup, newslot, InvalidBuffer, false); -- cgit v1.2.3