• Advertisement
Sign in to follow this  

memory leak detected

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement