Re: Memory leak in plpython3u (with testcase and patch)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mat Arye <mat@timescale.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-01-10T22:45:22Z
Lists: pgsql-hackers
Attachments
- v2-fix-plpython-memory-leaks.patch (text/x-diff) patch v2
I wrote: > However, I don't really see why we need to use that scratch context. > PLy_spi_execute_plan runs a subtransaction, so we could perfectly well > use the subtransaction's CurTransactionContext. Nah, I'm wrong about that: I forgot CurTransactionContext goes away on subtransaction abort, but not subtransaction commit. So we really need to make our own context with suitable lifespan. I also noticed that the code is moving heaven and earth to store the argument Datums ... but for some reason not the associated isnull flags ... in the PLyPlanObject. This is just nuts, because the values don't need to survive past the functions that are computing them. In the cursor case, the values will be copied into the cursor portal, so they still don't need to survive. We can drop all of that. So I arrive at the attached. (This is just for HEAD. In the back branches, we'd better leave the PLyPlanObject.values field in place for ABI safety, but we don't have to use it.) regards, tom lane
Commits
-
Repair memory leaks in plpython.
- e98df02df3f2 17.3 landed
- bcb4db0d379f 14.16 landed
- 71bb9c4b2a14 15.11 landed
- 33a4e656dc10 16.7 landed
- 29dfffae0a6d 18.0 landed
- 02a38bc84bef 13.19 landed