iterator problem

Zini

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.

Zini

29-11-2007 16:21:44

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

kungfoomasta

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? :)

Zini

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).

kungfoomasta

30-11-2007 03:09:12

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

kungfoomasta

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);
ConfigNode::~ConfigNode()


It should be as simple as replacing:


//Remove self from current parent
parent->children.erase(_iter);


with:


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


Did I miss something?

Zini

06-12-2007 23:07:42

That should work.

kungfoomasta

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.