memory leak detected

Started by
1 comment, last by abrken 19 years, 6 months ago
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.
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thank's for the speedy fix !

AbrKen.

This topic is closed to new replies.

Advertisement