henchman
March 13th, 2008, 02:47 AM
Hi :-)
Iam a Cpp beginner and trying to write a XML-Parser. Several days ago, i found a tool in these forums to find memory leaks in a program...
class XMLNode
{
XMLNode &getNextNode( )
{
// finding next node...
// ...
XMLNode* newNode = new XMLNode(/*params*/); // line of the memory leak according to valgrind
return *node;
}
char* xml;
char* startingPosition;
char* currentPosition;
char* endingPosition;
};
I had to copy the code by hand, so if there are typos, sorr.. the code runs...
My question is how can I return a reference/pointer of XMLNode in this function without memory loss... or do I have to return a normal (eg. non-pointer) XMLNode... I want to enable the user of this class to use it like this:
myNode.getNextNode().getNextNode()
There are exactly 16 Bytes lost according to valgrind... The pointers are filled with a value within the constructor and all point to the same char-array containing the xml-code, but the values behind these pointers are delete[]'d in another destructor...
Thanks for reading :)
Iam a Cpp beginner and trying to write a XML-Parser. Several days ago, i found a tool in these forums to find memory leaks in a program...
class XMLNode
{
XMLNode &getNextNode( )
{
// finding next node...
// ...
XMLNode* newNode = new XMLNode(/*params*/); // line of the memory leak according to valgrind
return *node;
}
char* xml;
char* startingPosition;
char* currentPosition;
char* endingPosition;
};
I had to copy the code by hand, so if there are typos, sorr.. the code runs...
My question is how can I return a reference/pointer of XMLNode in this function without memory loss... or do I have to return a normal (eg. non-pointer) XMLNode... I want to enable the user of this class to use it like this:
myNode.getNextNode().getNextNode()
There are exactly 16 Bytes lost according to valgrind... The pointers are filled with a value within the constructor and all point to the same char-array containing the xml-code, but the values behind these pointers are delete[]'d in another destructor...
Thanks for reading :)