Re: Xact end leaves CurrentMemoryContext = TopMemoryContext - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Xact end leaves CurrentMemoryContext = TopMemoryContext
Date
Msg-id 20240617214305.xb6cl6olizb6ij6i@awork3.anarazel.de
Whole thread Raw
In response to Xact end leaves CurrentMemoryContext = TopMemoryContext  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Reducing the log spam
Next
From: Greg Sabino Mullane
Date:
Subject: Re: cost delay brainstorming