1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Add memContextFreeing().

This can be used to determine if functions are running in a callback from memContextFree(). In this case, data in child mem contexts is not valid.
This commit is contained in:
David Steele 2020-08-05 14:07:04 -04:00
parent 6fc25c7a69
commit d74c8f4b58
3 changed files with 17 additions and 1 deletions

View File

@ -686,6 +686,19 @@ memContextCurrent(void)
FUNCTION_TEST_RETURN(memContextStack[memContextCurrentStackIdx].memContext);
}
/**********************************************************************************************************************************/
bool
memContextFreeing(MemContext *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(MEM_CONTEXT, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->state == memContextStateFreeing);
}
/**********************************************************************************************************************************/
const char *
memContextName(MemContext *this)

View File

@ -240,6 +240,9 @@ Memory context getters
// Current memory context
MemContext *memContextCurrent(void);
// Is the mem context currently being freed?
bool memContextFreeing(MemContext *this);
// Prior context, i.e. the context that was current before the last memContextSwitch()
MemContext *memContextPrior(void);

View File

@ -13,7 +13,7 @@ testFree(void *thisVoid)
{
MemContext *this = thisVoid;
TEST_RESULT_INT(this->state, memContextStateFreeing, "state should be freeing before memContextFree() in callback");
TEST_RESULT_BOOL(memContextFreeing(this), true, "state should be freeing before memContextFree() in callback");
memContextFree(this);
TEST_RESULT_INT(this->state, memContextStateFreeing, "state should still be freeing after memContextFree() in callback");