Re: memory leak in trigger handling (since PG12)
Tomas Vondra <tomas.vondra@enterprisedb.com>
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-05-23T20:57:31Z
Lists: pgsql-hackers
On 5/23/23 18:39, Tom Lane wrote: > Tomas Vondra <tomas.vondra@enterprisedb.com> writes: >> it seems there's a fairly annoying memory leak in trigger code, >> introduced by >> ... >> Attached is a patch, restoring the pre-12 behavior for me. > >> While looking for other places allocating stuff in ExecutorState (for >> the UPDATE case) and leaving it there, I found two more cases: > >> 1) copy_plpgsql_datums > >> 2) make_expanded_record_from_tupdesc >> make_expanded_record_from_exprecord > >> All of this is calls from plpgsql_exec_trigger. > > Not sure about the expanded-record case, but both of your other two > fixes feel like poor substitutes for pushing the memory into a > shorter-lived context. In particular I'm quite surprised that > plpgsql isn't already allocating that workspace in the "procedure" > memory context. > I don't disagree, but which memory context should this use and when/where should we switch to it? I haven't seen any obvious memory context candidate in the code calling ExecGetAllUpdatedCols, so I guess we'd have to pass it from above. Is that a good idea for backbranches ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Fix oversight in handling of modifiedCols since f24523672d
- 984c23f6f592 13.12 landed
- 260dbf19a5b4 14.9 landed
- 7ae4e786892f 15.4 landed
- 9cf85093b559 16.0 landed
- ce5aaea8cd32 17.0 landed
-
Use per-tuple context in ExecGetAllUpdatedCols
- f24523672de9 16.0 landed
- 54e1b8587234 12.16 landed
- c504aa857071 13.12 landed
- 7f528e96c501 14.9 landed
- ee87f8b63aee 15.4 landed
-
Generated columns
- fc22b6623b6b 12.0 cited