[xsd-users] memory leak in serializer.hxx
Mattia Tomasoni
tomasonimattia at googlemail.com
Mon Jun 13 08:58:12 EDT 2011
Dear codesynthesis users,
I am using a method of the class serializer
(examples/cxx/tree/streaming/serializer.hxx) to write an xml file:
template <typename T>
inline void serializer::
next (const std::string& ns, const std::string& name, const T& x)
{
xsd::cxx::xml::dom::auto_ptr<xercesc::DOMElement> e (create (ns, name));
*e << x;
serialize (*e);
}
the namespace, name of the element and the element itself are passed as
parameters. A pointer to a DOMElement is created, filled with the
information coming from the templetized parameter, and serialized (the
method serialize invokes DOMLSSerializer::write).
The above is invoked over an over on all the nodes of my document: as those
get written, the RAM starts filling up until the program is killed (for big
enough files).
If I comment the line:
*e << x;
no memory leak occurs and the output xml file is filled with empty elements
(with the specified name and namespace).
My guess: "e" points to an area of memory that is modified (in some
unorthodox way) by the "<<" operator and serialized to file. Once the job is
done, a delete on the pointer "e" will cause a memory fault. To obviate the
problem, codesynthesis created their own version of an auto_ptr that returns
responsibility to the programmer (by using release) instead of freeing the
memory. What to do?
Thank you for your time!
--
Mattia
More information about the xsd-users
mailing list