I haven't had the time to generate a simplified example of this bug yet, but I figured I would report it while I work on one.
I found that under certain conditions a "asBEHAVE_IMPLICIT_REF_CAST" behavior will leak. Here is what I know.
- There is no leak if I do not register any "asBEHAVE_IMPLICIT_REF_CAST" behavior.
- There is no leak if I do not register any template specializations.
- The leaked behavior is the one created during the registration of the template class, NOT the specialization.
It appears that registering the template specializations (or the asBEHAVE_IMPLICIT_REF_CAST behaviors in those specializations) is preventing the proper cleanup of the asBEHAVE_IMPLICIT_REF_CAST behaviors in the template class.
I will try to develop a simplified example, but there are a lot of elements involved. Let me know if you are able to reproduce the leak so I don't have create the example.
If there is anything I can
The leaked memory is allocated with the asNEW calls in asCScriptEngine::AddBehaviourFunction
int asCScriptEngine::AddBehaviourFunction(asCScriptFunction &func, asSSystemFunctionInterface &internal)
{
asUINT n;
int id = GetNextScriptFunctionId();
asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal);
if( newInterface == 0 )
return asOUT_OF_MEMORY;
asCScriptFunction *f = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM);
if( f == 0 )
{
asDELETE(newInterface, asSSystemFunctionInterface);
return asOUT_OF_MEMORY;
}
asASSERT(func.name != "" && func.name != "f");
f->name = func.name;
f->sysFuncIntf = newInterface;
f->returnType = func.returnType;
f->objectType = func.objectType;
f->id = id;
f->isReadOnly = func.isReadOnly;
f->accessMask = defaultAccessMask;
f->parameterTypes = func.parameterTypes;
f->inOutFlags = func.inOutFlags;
for( n = 0; n < func.defaultArgs.GetLength(); n++ )
if( func.defaultArgs[n] )
f->defaultArgs.PushLast(asNEW(asCString)(*func.defaultArgs[n]));
else
f->defaultArgs.PushLast(0);
SetScriptFunction(f);
// If parameter type from other groups are used, add references
if( f->returnType.GetObjectType() )
{
asCConfigGroup *group = FindConfigGroupForObjectType(f->returnType.GetObjectType());
currentGroup->RefConfigGroup(group);
}
for( n = 0; n < f->parameterTypes.GetLength(); n++ )
{
if( f->parameterTypes[n].GetObjectType() )
{
asCConfigGroup *group = FindConfigGroupForObjectType(f->parameterTypes[n].GetObjectType());
currentGroup->RefConfigGroup(group);
}
}
return id;
}
I have attached my engine configuration. I have reduced it quite a bit, but it still shows the leak. I am noticing that even though I registered a template specilization Array<int8> it doesn't show in the configuration file. I hope this helps.