src/backend/utils/mmgr/mcxt.c
bool
MemoryContextContains(MemoryContext context, void *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;
}
/*
 * MemoryContextContains
 *		Detect whether an allocated chunk of memory belongs to a given
 *		context or not.
 *
 * Caution: this test is reliable as long as 'pointer' does point to
 * a chunk of memory allocated from *some* context.  If 'pointer' points
 * at memory obtained in some other way, there is a small chance of a
 * false-positive result, since the bits right before it might look like
 * a valid chunk header by chance.
 */
MemoryContextContains
Detect whether an allocated chunk of memory belongs to a given
context or not.

this test is reliable as long as 'pointer' does point to
a chunk of memory allocated from *some* context.  If 'pointer' points
at memory obtained in some other way, there is a small chance of a
false-positive result, since the bits right before it might look like
a valid chunk header by chance.
MemoryContextContains Detect whether an allocated chunk of memory belongs to a given context or not . this test is reliable as long as ' pointer ' does point to a chunk of memory allocated from * some * context . If ' pointer ' points at memory obtained in some other way there is a small chance of a false - positive result since the bits right before it might look like a valid chunk header by chance .
bool
MemoryContextContains(MemoryContext context, void *pointer)
{
	MemoryContext ptr_context;
	if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
		return false;
	ptr_context = *(MemoryContext *) (((char *) pointer) - sizeof(void *));
	return ptr_context == context;
}
bool MemoryContextContains ( MemoryContext context , void * pointer ) { MemoryContext ptr_context ; if ( pointer == NULL || pointer != ( void * ) MAXALIGN ( pointer ) ) return false ; ptr_context = * ( MemoryContext * ) ( ( ( char * ) pointer ) - sizeof ( void * ) ) ; return ptr_context == context ; }
MemoryContextContains
              Detect whether an allocated chunk of memory belongs to a given
              context or not.
MemoryContextContains Detect whether an allocated chunk of memory belongs to a given context or not .
/*
	 * 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.
	 */ /*
	 * OK, it's probably safe to look at the context.
	 */