diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-04-21 11:34:36 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-04-21 11:34:36 -0400 |
commit | 5ec8b01c30e7ea34bb42592ad9d34d4b02ea593d (patch) | |
tree | d2e47852d18582145ceb6a3c68225d05e1292248 /src | |
parent | 706cbed351037fb5e886815506515d1281e62d40 (diff) | |
download | postgresql-5ec8b01c30e7ea34bb42592ad9d34d4b02ea593d.tar.gz postgresql-5ec8b01c30e7ea34bb42592ad9d34d4b02ea593d.zip |
MemoryContextCreate: assert parent is valid and different from node.
The case of "node == parent" might seem impossible, since we just
allocated the new node. But it's possible if parent is a dangling
reference to a recently-deleted context. In fact, given aset.c's
habit of recycling contexts, it's actually rather likely if that's so.
If we'd had this assertion before, it would have simplified debugging
a recently-identified walsender issue.
Reported-by: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAO6_XqoJA7-_G6t7Uqe5nWF3nj+QBGn4F6Ptp=rUGDr0zo+KvA@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 68f1cbcf9c2..506f2902986 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -1181,6 +1181,10 @@ MemoryContextCreate(MemoryContext node, /* Creating new memory contexts is not allowed in a critical section */ Assert(CritSectionCount == 0); + /* Validate parent, to help prevent crazy context linkages */ + Assert(parent == NULL || MemoryContextIsValid(parent)); + Assert(node != parent); + /* Initialize all standard fields of memory context header */ node->type = tag; node->isReset = true; |