1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Assert correct VM page passed to pruning

Before pruning a heap page, we get the current status of the
corresponding VM page. If the passed in vmbuffer isn't the right one,
visibilitymap_get_status() will silently unpin it and pin the correct
page. Pruning assumes the caller manages the vmbuffer lifecycle, so this
would leave the caller with a stale VM reference and would leak the new
VM pin. To avoid mistakes in development, assert that the correct VM
page is pinned before beginning.

Reported-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://postgr.es/m/CAAKRu_amj7qLF4c=9ijd=708Fu2G8gg-2EqwBu=aCdAHU2sPHg@mail.gmail.com
Backpatch-through: 19
This commit is contained in:
Melanie Plageman
2026-09-22 17:27:26 -04:00
parent 09a579abac
commit d8516db39d

View File

@@ -443,7 +443,13 @@ prune_freeze_setup(PruneFreezeParams *params,
prstate->buffer = params->buffer;
prstate->page = BufferGetPage(params->buffer);
Assert(BufferIsValid(params->vmbuffer));
/*
* The caller must have pinned the VM page covering this heap block. If it
* doesn't have the correct page pinned, visibilitymap_get_status() will
* silently release the caller's pin and take its own, leaving the caller
* holding a stale buffer and leaking ours.
*/
Assert(visibilitymap_pin_ok(prstate->block, params->vmbuffer));
prstate->vmbuffer = params->vmbuffer;
prstate->new_vmbits = 0;
prstate->old_vmbits = visibilitymap_get_status(prstate->relation,