Hi, On 2024-06-17 16:37:05 -0400, Tom Lane wrote: > As to what to do about it: I'm imagining that instead of resetting > CurrentMemoryContext to TopMemoryContext, we set it to some special > context that we expect we can reset every so often, like at the start > of the next transaction. The existing TransactionAbortContext is > a very similar thing, and maybe could be repurposed/shared with this > usage.
One issue is that that could lead to hard to find use-after-free issues in currently working code. Right now allocations made "between transactions" live forever, if we just use a different context it won't anymore. Particularly if the reset is only occasional, we'd make it hard to find buggy allocations. I wonder if we ought to set CurrentMemoryContext to NULL in that timeframe, forcing code to explicitly choose what lifetime is needed, rather than just defaulting such code into changed semantics. Greetings, Andres Freund