plperl: don't save and re-use temp context in return_next(). Commit ebdefb93b arranged to run plperl_return_next_internal() in a temporary memory context that got reset at the end of each call, so as not to accumulate lots of leaked memory in a PL/Perl function that returns many rows. But this arrangement is unsafe because re-entrant calls of return_next are possible, as shown by the new regression test. In that case the inner call's reset destroys data the outer call still needs, leading to crashes. Instead, just create and delete a temp context for each call. That works correctly in the nested case, and in the normal case it's not really much slower than the old way thanks to the context recycling logic in aset.c (which long postdates ebdefb93b, but is in every still-supported branch).
Reported-by: Anthropic OSS program Author: Anthropic OSS program Reviewed-by: Tom Lane <[email protected]> Backpatch-through: 14 Security: CVE-2026-116319 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/eab8001348eed01401e06b4aa4876817dff005ba Author: Tom Lane <[email protected]> Modified Files -------------- src/pl/plperl/expected/plperl_tied.out | 21 +++++++++++++++++++++ src/pl/plperl/plperl.c | 22 ++++++++++++---------- src/pl/plperl/sql/plperl_tied.sql | 17 +++++++++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-)
