Memory leak in IrrXMLReader

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Memory leak in IrrXMLReader

Post by Nyxojaele »

It would appear there's a memory leak in IrrXMLReader. I write this simple program:
(The XML file exists, and is valid, as I've used it fine in other programs, but that doesn't really matter, since the same problem occurs if the file doesn't exist...)

Code: Select all

int main() {
	IrrXMLReader *xml = createIrrXMLReader("c:\\projects\\PACNyx\\debug\\options.pnoptions");
	delete xml;
	return 0;
}
And my output window tells me this after the program has exited:

Code: Select all

Detected memory leaks!
Dumping objects ->
.\irrXML.cpp(86) : {151} client block at 0x003A6DF8, subtype 0, 16 bytes long.
 Data: <X 7   :         > 58 E6 37 10 E8 F6 3A 10 0C 02 00 00 01 CD CD CD 
Object dump complete.
Detected memory leaks!
Dumping objects ->
.\irrXML.cpp(86) : {151} client block at 0x003A6DF8, subtype 0, 16 bytes long.
 Data: <X 7   :         > 58 E6 37 10 E8 F6 3A 10 0C 02 00 00 01 CD CD CD 
Object dump complete.
The program '[0xAA8] PACNyxPlus.exe: Native' has exited with code 0 (0x0).
Looking at the line the output window points me at, it would appear that there is no implemented means for the CFileReadCallBack created via 'new' in the following code to be deleted when everything is done with it (correct me if I'm wrong...):

Code: Select all

IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename)
{
	return createIrrXMLReader(new CFileReadCallBack(filename)); 
}
I can see that in the later call to the Constructor of CXMLReaderImpl that the callback could potentially be deleted, but it's boolean parameter "deleteCallBack"is set to "false" by the calling function, so it doesn't get deleted. The callback never gets stored anywhere, and it's pointer is lost after this Constructor is called.
radical-dev
Posts: 45
Joined: Thu Apr 24, 2008 7:54 pm
Location: Wickede, Germany

Post by radical-dev »

Hi!

Wasn't it so that within the Irrlicht-API everything what is created via "createXXX" has to be dropped (e.g. xml->drop()).

I haven't looked at the source so far, so it could be wrong ;-)
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Memory leak in IrrXMLReader

Post by rogerborg »

Nyxojaele wrote:Looking at the line the output window points me at, it would appear that there is no implemented means for the CFileReadCallBack created via 'new' in the following code to be deleted when everything is done with it (correct me if I'm wrong...):
Nope, I can't see it either. The callback isn't stored anywhere, and doesn't appear to be used after the readFile().

I've added cleanup to the 1.5 branch in SVN 2176. Thanks for the report.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Post by Nyxojaele »

@radical-dev
The IrrXMLReader was designed specifically to be used without an IrrlichtDevice, and thus, doesn't inherit from IReferenceCounted, which is what gives the objects their grab() and drop() methods. So the only way to clean it up is to delete it. It's shown in the API, actually.
Please note that there is also an IXMLReader which does inherit from IReferenceCounted, which may be what you're thinking of...

@rogerborg
No problem- glad to be of help.
So, since it doesn't appear to be used after readFile(), then I would assume that the correct fix would be just to set the calling function to send a true value for deleteCallBack, instead of the false that it's currently set to, ne? I wonder why it was set to false in the first place, then... *ponders*
Post Reply