From: Andres Freund Date: Wed, 1 Mar 2017 04:41:44 +0000 (-0800) Subject: Fix assertion failure due to over-eager code deduplication. X-Git-Tag: REL_10_BETA1~811 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=123ccbe58309d08e42009e99a4b34a3a1aef7798;p=postgresql 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. --- diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 07732ba59b..6668bf135e 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -566,7 +566,24 @@ MemoryContextCheck(MemoryContext context) bool MemoryContextContains(MemoryContext context, void *pointer) { - MemoryContext ptr_context = GetMemoryChunkContext(pointer); + MemoryContext ptr_context; + + /* + * NB: Can't use GetMemoryChunkContext() here - that performs assertions + * that aren't acceptable here since we might be passed memory not + * allocated by any memory context. + * + * Try to detect bogus pointers handed to us, poorly though we can. + * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an + * allocated chunk. + */ + if (pointer == NULL || pointer != (void *) MAXALIGN(pointer)) + return false; + + /* + * OK, it's probably safe to look at the context. + */ + ptr_context = *(MemoryContext *) (((char *) pointer) - sizeof(void *)); return ptr_context == context; }