Sign in to follow this  
abrken

memory leak detected

Recommended Posts

Hello, For many time now, I was getting memory leaks. I was knowing that those memory leaks came from AS but never figured out how this happens. Finally, I have found where the memory leak take place, and how to reproduce it. This is the code (from test_constructor.cpp) :
bool TestConstructor()
{
	bool fail = false;

	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	RegisterStdString(engine);

	int r;
	r = engine->RegisterObjectType("obj", sizeof(CTestConstructor), asOBJ_CLASS_C); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONP(ConstrObj, (CTestConstructor *)), asCALL_CDECL_OBJLAST); assert( r >= 0 );
	r = engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(int,int)", asFUNCTIONP(ConstrObj, (int, int, CTestConstructor *)), asCALL_CDECL_OBJLAST); assert( r >= 0 );
	r = engine->RegisterObjectProperty("obj", "int a", offsetof(CTestConstructor, a)); assert( r >= 0 );
	r = engine->RegisterObjectProperty("obj", "int b", offsetof(CTestConstructor, b)); assert( r >= 0 );

	int a, b;
	r = engine->RegisterGlobalProperty("int a", &a); assert( r >= 0 );
	r = engine->RegisterGlobalProperty("int b", &b); assert( r >= 0 );

	CBufferedOutStream out;	
	engine->AddScriptSection(0, TESTNAME, script1, strlen(script1), 0);

	engine->Release();

	// Success
	return fail;
}

The memory leak come from the fact that a Script Section is added and nothing else (no Build, nor Execute) is made with the engine. It seems that the
new asCScriptCode
that appear in as_builder::AddCode is never deleted. Regards, AbrKen.

Share this post


Link to post
Share on other sites
Thanks for letting me know.

I've found and fixed the problem.

The change needed is the addition of the following statements in asCModule::~asCModule() right after Reset();


if( builder )
{
delete builder;
builder = 0;
}



Regards,
Andreas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this