iterator problem


29-11-2007 16:16:09

I am still on an older revision of QuickGUI, but out of curiosity I have made another checkout of the current version to browse the code a bit.

While browsing I found a very serious issue in ConfigNode. The class has a vector and an iterator for this vector (or actually for the vector of the parent Node), which is initialised in the constructor. As soon as something is inserted or removed from this vector the iterator has a chance to get invalid, which means we have a potential dangling pointer in the ConfigNode object.


29-11-2007 16:21:44

And since we are at it, ConfigScriptLoader::parseScript has a memory leak (parseBuff).


29-11-2007 17:39:36

Thanks for pointing these out. I'm not familiar with that portion of code, but I'll take a look, it's probably a quick fix right? :)


29-11-2007 18:02:15

The memory leak yes. The iterator stuff a bit less. You will have to remove it from the class, which means you will have to rewrite other parts too (at least two functions).


30-11-2007 03:09:12

Fixed the memory leak. Will look at the other issue later, short on time today.


06-12-2007 23:03:41

Any suggested solutions to this issue? I just read through the code, but I'll need a short while to digest it..

The iterator is only being used in two functions:

void ConfigNode::setParent(ConfigNode *newParent);

It should be as simple as replacing:

//Remove self from current parent


for(std::vector<ConfigNode*>::iterator it = parent->children.begin(); it != parent->children.end(); ++it)
if((*it) == this)

Did I miss something?


06-12-2007 23:07:42

That should work.


07-12-2007 08:57:24

Seems to be working with the fix. I'm not sure if I would check out from SVN though.