Skip to content

Commit 123ccbe

Browse files
committed
Fix assertion failure due to over-eager code deduplication.
In the previous commit I'd made MemoryContextContains() use GetMemoryChunkContext(), but that causes trouble when the passed pointer isn't allocated in any memory context - that's probably something we shouldn't do, but the previous commit isn't a place for a "policy" change.
1 parent f4e2d50 commit 123ccbe

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/utils/mmgr/mcxt.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,24 @@ MemoryContextCheck(MemoryContext context)
566566
bool
567567
MemoryContextContains(MemoryContext context, void *pointer)
568568
{
569-
MemoryContext ptr_context = GetMemoryChunkContext(pointer);
569+
MemoryContext ptr_context;
570+
571+
/*
572+
* NB: Can't use GetMemoryChunkContext() here - that performs assertions
573+
* that aren't acceptable here since we might be passed memory not
574+
* allocated by any memory context.
575+
*
576+
* Try to detect bogus pointers handed to us, poorly though we can.
577+
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
578+
* allocated chunk.
579+
*/
580+
if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
581+
return false;
582+
583+
/*
584+
* OK, it's probably safe to look at the context.
585+
*/
586+
ptr_context = *(MemoryContext *) (((char *) pointer) - sizeof(void *));
570587

571588
return ptr_context == context;
572589
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy