Use MEM_CONTEXT_BEGIN() block in varFree().
We probably arrived at this unusual construction because of the complexity of getting the mem context.  Whether or not this is a good way to store the mem context, it still makes sense to use the standard pattern for switching mem contexts.
@@ -1234,77 +1234,73 @@ varFree(Variant *this)
if (this != NULL)
{
- MemContext *contextOld = memContextCurrent();
+ MemContext *memContext = NULL;
- TRY_BEGIN()
- {
switch (this->type)
{
case varTypeBool:
{
- memContextSwitch(((VariantBool *)this)->memContext);
+ memContext = ((VariantBool *)this)->memContext;
break;
}
case varTypeDouble:
{
- memContextSwitch(((VariantDouble *)this)->memContext);
+ memContext = ((VariantDouble *)this)->memContext;
break;
}
case varTypeInt:
{
- memContextSwitch(((VariantInt *)this)->memContext);
+ memContext = ((VariantInt *)this)->memContext;
break;
}
case varTypeInt64:
{
- memContextSwitch(((VariantInt64 *)this)->memContext);
+ memContext = ((VariantInt64 *)this)->memContext;
break;
}
case varTypeKeyValue:
{
- memContextSwitch(((VariantKeyValue *)this)->memContext);
+ memContext = ((VariantKeyValue *)this)->memContext;
kvFree(((VariantKeyValue *)this)->data);
break;
}
case varTypeString:
{
- memContextSwitch(((VariantString *)this)->memContext);
+ memContext = ((VariantString *)this)->memContext;
strFree(((VariantString *)this)->data);
break;
}
case varTypeUInt:
{
- memContextSwitch(((VariantUInt *)this)->memContext);
+ memContext = ((VariantUInt *)this)->memContext;
break;
}
case varTypeUInt64:
{
- memContextSwitch(((VariantUInt64 *)this)->memContext);
+ memContext = ((VariantUInt64 *)this)->memContext;
break;
}
case varTypeVariantList:
{
- memContextSwitch(((VariantVariantList *)this)->memContext);
+ memContext = ((VariantVariantList *)this)->memContext;
varLstFree(((VariantVariantList *)this)->data);
break;
}
}
- memFree(this);
- }
- FINALLY()
+ MEM_CONTEXT_BEGIN(memContext)
{
- memContextSwitch(contextOld);
+ memFree(this);
}
- TRY_END();
+ MEM_CONTEXT_END();
}
FUNCTION_TEST_RETURN_VOID();
