Skip to content

Commit cce7486

Browse files
committed
Fix race condition in DELETE RETURNING.
When RETURNING is specified, ExecDelete would return a virtual-tuple slot that could contain pointers into an already-unpinned disk buffer. Another process could change the buffer contents before we get around to using the data, resulting in garbage results or even a crash. This seems of fairly low probability, which may explain why there are no known field reports of the problem, but it's definitely possible. Fix by forcing the result slot to be "materialized" before we release pin on the disk buffer. Back-patch to 9.0; in earlier branches there is no bug because ExecProcessReturning sent the tuple to the destination immediately. Also, this is already fixed in HEAD as part of the writable-foreign-tables patch (where the fix is necessary for DELETE RETURNING to work at all with postgres_fdw).
1 parent ef2a82b commit cce7486

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ ldelete:;
439439
rslot = ExecProcessReturning(resultRelInfo->ri_projectReturning,
440440
slot, planSlot);
441441

442+
/*
443+
* Before releasing the target tuple again, make sure rslot has a
444+
* local copy of any pass-by-reference values.
445+
*/
446+
ExecMaterializeSlot(rslot);
447+
442448
ExecClearTuple(slot);
443449
if (BufferIsValid(delbuffer))
444450
ReleaseBuffer(delbuffer);

0 commit comments

Comments
 (0)