model-writtenrun 3273 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Nikita Kalinin reported a PL/pgSQL heap-use-after-free on PostgreSQL 16.3, providing a reproducer that drops a called function and recreates it as set-returning in #1.
- Tom Lane simplified the reproduction to one session without ASAN and identified missing query-simplicity checks during plan revalidation, proposing that all such checks be repeated in #2.
- Tom Lane also identified dangling expression pointers left after an error while processing the changed plan, explaining why a subsequent call could access freed memory in #2.
- The patch in #2 extracted exec_is_simple_query, cleared vulnerable state before replanning, and added regression tests; Tom verified the cleanup independently by temporarily disabling the new simplicity check.
- The thread ends with Tom's proposed fix in #2, which subsequently landed as 82a931d3d2 with simplified CachedPlanSource handling and unchanged regression tests, with backports to all supported branches.