David Bertoni wrote:
> The first thing I noted with your code is that it's full of memory leaks
> of this variety:
<snip>

You're right! I've totally missed them!

> Also, I would suggest that rather than transcoding these hard-coded
> strings at run-time, that you create versions of these strings that are
> already encoded in UTF-16 at compile time.  You can use the constants
> defined in xerces/util/XMLUniDefs.hpp.  For an example of what I mean,
> take a look at XMLUni.cpp in the same directory.

That's a good suggestion, I did so and now it works perfectly.

> The reason the file is empty is because you never destroy the
> LocalFileFormatTarget, so the underlying file is not closed until the
> process exits.  This is also a memory leak, and you have a memory leak
> when you construct it, because you call XMLString::transcode() and you
> don't release the pointer that's returned:
> 
> target_ = new LocalFileFormatTarget(XMLString::transcode(xmlFile.c_str()));
> 
> You can make your life easier by creating the LocalFileFormatTarget on
> the stack, instead of on the heap.  It's a small object, so there's no
> danger in overflowing the stack.

Same as above!

> A few other comments, while I'm on a roll:
> 
> void
> XMLParser::destroyInstance()
> {
>   if(instance_)
>     delete(instance_);
> 
>   instance_ = 0;
> }
> 
> It's never necessary in C++ to check a pointer for null before deleting
> it.  The compiler already has to do this, so why have your code do it too?

Doh! I read it on Parashift's FAQ too, but I was so busy trying to
resolve segmentation faults that I forgot it!

> if(current->getNodeType() != 0 && current->getNodeType() ==
> DOMNode::ELEMENT_NODE)
> 
> I'm not sure why you're checking for a node type that's not equal to 0
> then checking for one that's equal to DOMNode::ELEMENT_NODE.
> getNodeType() return an enum, and an enum can only have a single value,
> so the only test you need is for DOMNode::ELEMENT_NODE.

It's a remnant of previous experiments, it happens quite often to me
that I start with clean and well structured code and quickly degrade
it... Ok, I'm not a Real Programmer (TM) :P
Thank you very very much for your precious help, I would have gone crazy
trying to fix those bug by myself!!
                                Roberto

Reply via email to