aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-02-28 20:41:44 -0800
committerAndres Freund <andres@anarazel.de>2017-02-28 20:43:18 -0800
commit123ccbe58309d08e42009e99a4b34a3a1aef7798 (patch)
tree37d32a9bb0dbbfd192c7e6cce07b96ee7ddbbe37
parentf4e2d50cd7483a068c0a32e56b2d40f980cdea72 (diff)
downloadpostgresql-123ccbe58309d08e42009e99a4b34a3a1aef7798.tar.gz
postgresql-123ccbe58309d08e42009e99a4b34a3a1aef7798.zip
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.
-rw-r--r--src/backend/utils/mmgr/mcxt.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 07732ba59bc..6668bf135e9 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;
}