I am using BoundsChecker and if I load a file and make clone of any child it is showing leak in Clone. Do I need to destroy the cloned node myself if yes then how?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Again, example code would make this easier to diagnose.
In the absence of that, I'll take a guess...
If you do
{
thing = new TiXmlNode();
}
You have a leak.
But this will not have a leak:
{
thing = new TiXmlNode();
delete thing;
}
Similarly, this:
{
thing = src->Clone();
}
is clearly a leak, but the following is not:
{
thing = src->Clone();
delete thing;
}
Recall the doc from TinyXml.h:
/** Create an exact duplicate of this node and return it. The memory must be deleted
by the caller.
*/
virtual TiXmlNode* Clone() const = 0;
alternatively, if you make the node owned by something else that gets cleaned up (either by explicit deleting or by implict deleting when the stack is unwound) then you'll have no leak:
{
TiXmlDocument doc;
...
TiXmlElement copy = someNode->Clone()
doc->LinkEndChild(copy); // node is now "owned"
} // doc will be deleted as stack unwinds, and as doc owns copy, then copy will be deleted
HTH
Ellers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am getting memory leak in TinyXml if I clone a node.
Is this going to be fixed?
Thanks in Advance!
Can you be more specific?
Example code that clearly reproduces the leak, for example.
Ellers
I am using BoundsChecker and if I load a file and make clone of any child it is showing leak in Clone. Do I need to destroy the cloned node myself if yes then how?
Again, example code would make this easier to diagnose.
In the absence of that, I'll take a guess...
If you do
{
thing = new TiXmlNode();
}
You have a leak.
But this will not have a leak:
{
thing = new TiXmlNode();
delete thing;
}
Similarly, this:
{
thing = src->Clone();
}
is clearly a leak, but the following is not:
{
thing = src->Clone();
delete thing;
}
Recall the doc from TinyXml.h:
/** Create an exact duplicate of this node and return it. The memory must be deleted
by the caller.
*/
virtual TiXmlNode* Clone() const = 0;
alternatively, if you make the node owned by something else that gets cleaned up (either by explicit deleting or by implict deleting when the stack is unwound) then you'll have no leak:
{
TiXmlDocument doc;
...
TiXmlElement copy = someNode->Clone()
doc->LinkEndChild(copy); // node is now "owned"
} // doc will be deleted as stack unwinds, and as doc owns copy, then copy will be deleted
HTH
Ellers