Fix crash when non-creator being an iteration on shared radix tree

Masahiko Sawada <sawada.mshk@gmail.com>

From: Masahiko Sawada <sawada.mshk@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2024-12-17T17:48:22Z
Lists: pgsql-hackers

Attachments

Hi,

I found that a server crashes due to a null-pointer-dereference if a
process attached to the shared radix tree begins an iteration on it,
because we don't create the memory context for iter_context at
RT_ATTACH(). There is no code in the core causing this crash in the
core since in parallel vacuum, the leader process always creates the
shared radix tree and begins the iteration. However it could happen in
external extensions. I've attached the patch to fix it and I think it
should be backpatched to v17.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Commits

  1. radixtree: Fix crash when non-creator begins iteration over shared tree.

  2. Always use the caller-provided context for radix tree leaves

  3. Get rid of radix tree's general purpose memory context

  4. Use caller's memory context for radix tree iteration state