Fix oversight in handling of modifiedCols since f24523672d
authorTomas Vondra <tomas.vondra@postgresql.org>
Sun, 2 Jul 2023 18:29:01 +0000 (20:29 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Sun, 2 Jul 2023 20:23:04 +0000 (22:23 +0200)
commit260dbf19a5b4269feb6d29887aed94454602d8ac
tree2dfc21c0be5692f8a2cf42a82e27bfede0075a61
parentc1affa38c73b432d358c5b19b697e03a59b355ab
Fix oversight in handling of modifiedCols since f24523672d

Commit f24523672d fixed a memory leak by moving the modifiedCols bitmap
into the per-row memory context. In the case of AFTER UPDATE triggers,
the bitmap is however referenced from an event kept until the end of the
query, resulting in a use-after-free bug.

Fixed by copying the bitmap into the AfterTriggerEvents memory context,
which is the one where we keep the trigger events. There's only one
place that needs to do the copy, but the memory context may not exist
yet. Doing that in a separate function seems more readable.

Report by Alexander Pyhalov, fix by me. Backpatch to 13, where the
bitmap was added to the event by commit 71d60e2aa0.

Reported-by: Alexander Pyhalov
Backpatch-through: 13
Discussion: https://postgr.es/m/acddb17c89b0d6cb940eaeda18c08bbe@postgrespro.ru
src/backend/commands/trigger.c