diff options
Diffstat (limited to 'src/backend/utils/mmgr/mcxt.c')
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 8dd3cf48896..c72e3470004 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -569,6 +569,8 @@ MemoryContextCreate(NodeTag tag, Size size, void * MemoryContextAlloc(MemoryContext context, Size size) { + void *ret; + AssertArg(MemoryContextIsValid(context)); if (!AllocSizeIsValid(size)) @@ -577,7 +579,9 @@ MemoryContextAlloc(MemoryContext context, Size size) context->isReset = false; - return (*context->methods->alloc) (context, size); + ret = (*context->methods->alloc) (context, size); + + return ret; } /* @@ -638,6 +642,8 @@ void * palloc(Size size) { /* duplicates MemoryContextAlloc to avoid increased overhead */ + void *ret; + AssertArg(MemoryContextIsValid(CurrentMemoryContext)); if (!AllocSizeIsValid(size)) @@ -646,7 +652,9 @@ palloc(Size size) CurrentMemoryContext->isReset = false; - return (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size); + ret = (*CurrentMemoryContext->methods->alloc) (CurrentMemoryContext, size); + + return ret; } void * @@ -677,7 +685,7 @@ palloc0(Size size) void pfree(void *pointer) { - StandardChunkHeader *header; + MemoryContext context; /* * Try to detect bogus pointers handed to us, poorly though we can. @@ -690,12 +698,12 @@ pfree(void *pointer) /* * OK, it's probably safe to look at the chunk header. */ - header = (StandardChunkHeader *) - ((char *) pointer - STANDARDCHUNKHEADERSIZE); + context = ((StandardChunkHeader *) + ((char *) pointer - STANDARDCHUNKHEADERSIZE))->context; - AssertArg(MemoryContextIsValid(header->context)); + AssertArg(MemoryContextIsValid(context)); - (*header->context->methods->free_p) (header->context, pointer); + (*context->methods->free_p) (context, pointer); } /* @@ -705,7 +713,12 @@ pfree(void *pointer) void * repalloc(void *pointer, Size size) { - StandardChunkHeader *header; + MemoryContext context; + void *ret; + + if (!AllocSizeIsValid(size)) + elog(ERROR, "invalid memory alloc request size %lu", + (unsigned long) size); /* * Try to detect bogus pointers handed to us, poorly though we can. @@ -718,20 +731,17 @@ repalloc(void *pointer, Size size) /* * OK, it's probably safe to look at the chunk header. */ - header = (StandardChunkHeader *) - ((char *) pointer - STANDARDCHUNKHEADERSIZE); + context = ((StandardChunkHeader *) + ((char *) pointer - STANDARDCHUNKHEADERSIZE))->context; - AssertArg(MemoryContextIsValid(header->context)); - - if (!AllocSizeIsValid(size)) - elog(ERROR, "invalid memory alloc request size %lu", - (unsigned long) size); + AssertArg(MemoryContextIsValid(context)); /* isReset must be false already */ - Assert(!header->context->isReset); + Assert(!context->isReset); + + ret = (*context->methods->realloc) (context, pointer, size); - return (*header->context->methods->realloc) (header->context, - pointer, size); + return ret; } /* |