[
https://issues.apache.org/jira/browse/XERCESC-1451?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=12901912#action_12901912
]
Daniel Pinyol commented on XERCESC-1451:
I have the same problem running the code of listing1 in
http://www.ibm.com/developerworks/xml/library/x-serial.html
I only replaced the parse line with
xercesc::DOMNode *aDOMNode = (xercesc::DOMNode*)
myParser-parse(theXMLFile.xml)-getDocumentElement();
and added a loop to be able to call writeTostring several times.
valgrind reports an error (in both xerces 2.7 2.8), but only on the first
call to writeToString :
Probably a bug in xerces initialization
==17266== Mismatched free() / delete / delete []
==17266==at 0x40244D3: operator delete[](void*)
(vg_replace_malloc.c:409)
==17266==by 0x42C0347: xercesc_2_8::XMLString::release(unsigned
short**) (in /usr/lib/libxerces-c.so.28.0)
==17266==by 0x8048BE0: main (in
/home/dani/svn/sandbox/src/common/xerces/a.out)
==17266== Address 0x581f9e8 is 0 bytes inside a block of size 46 alloc'd
==17266==at 0x402569A: operator new(unsigned int)
(vg_replace_malloc.c:255)
==17266==by 0x42091CC:
xercesc_2_8::MemoryManagerImpl::allocate(unsigned int) (in
/usr/lib/libxerces-c.so.28.0)
==17266==by 0x41B0820:
xercesc_2_8::DOMWriterImpl::writeToString(xercesc_2_8::DOMNode const) (in
/usr/lib/libxerces-c.so.28.0)
==17266==by 0x8048BD0: main (in
/home/dani/svn/sandbox/src/common/xerces/a.out)
#include xercesc/dom/DOMNodeList.hpp
#include xercesc/dom/DOMNamedNodeMap.hpp
#include xercesc/dom/DOMComment.hpp
#include xercesc/dom/DOMText.hpp
#include xercesc/dom/DOMImplementation.hpp
#include xercesc/dom/DOMImplementationRegistry.hpp
#include xercesc/dom/DOMBuilder.hpp
#include xercesc/dom/DOMWriter.hpp
#include xercesc/dom/DOMError.hpp
#include xercesc/dom/DOMErrorHandler.hpp
#include xercesc/dom/DOMDocument.hpp
#include xercesc/dom/DOMLocator.hpp
#include xercesc/sax/SAXException.hpp
#include xercesc/framework/Wrapper4InputSource.hpp
#include xercesc/framework/MemBufInputSource.hpp
#include xercesc/util/XMLUniDefs.hpp
#include xercesc/util/PlatformUtils.hpp
#include stdlib.h
using namespace xercesc;
int main(int argc, char **argv)
{
xercesc::XMLPlatformUtils::Initialize(0,0,0,0, true);
// DOMImplementationLS contains factory methods for creating objects
// that implement the DOMBuilder and the DOMWriter interfaces
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
// construct the DOMBuilder
DOMBuilder* myParser = ((DOMImplementationLS*)impl)-
createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
// parse the XML data, assume it is saved in a local file
// called theXMLFile.xml
// the DOMBuilder will parse the data and return it as a DOM tree
xercesc::DOMNode *aDOMNode = (xercesc::DOMNode*)
myParser-parseURI(theXMLFile.xml)-getDocumentElement();
//DOMNode* aDOMNode = myParser-parseURI(theXMLFile.xml);
// construct the DOMWriter
DOMWriter* myWriter = ((DOMImplementationLS*)impl)-createDOMWriter();
// optionally, set some DOMWriter features
// set the format-pretty-print feature
if (myWriter-canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
myWriter-setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// set the byte-order-mark feature
if (myWriter-canSetFeature(XMLUni::fgDOMWRTBOM, true))
myWriter-setFeature(XMLUni::fgDOMWRTBOM, true);
int times =1;
if (argc 1)
times= atoi(argv[1]);
// serialize the DOMNode to a UTF-16 string
for (int i=0; i times; i++)
{
XMLCh* theXMLString_Unicode = myWriter-writeToString(*aDOMNode);
// release the memory
XMLString::release(theXMLString_Unicode);
}
myWriter-release();
myParser-release();
xercesc::XMLPlatformUtils::Terminate();
}
Valgrind reports mismatched new/delete[] usage
--
Key: XERCESC-1451
URL: https://issues.apache.org/jira/browse/XERCESC-1451
Project: Xerces-C++
Issue Type: Bug
Affects Versions: 2.5.0, 2.6.0
Environment: Red Hat 9 (Shrike 2.4.20-6smp), Dell Precision 530
Valgrind 2.4.0
g++ 3.2.2
Reporter: Glenn Miyake
Valgrind reports a mismatch new/delete[]
MemoryManagerImpl::allocate(unsigned) appears to allocate using just
new(size).
This memory is then incorrectly freed using array delete (delete []) in
XMLString::release.
Simply changing the release method to call delete does not work since it
appears that release is also used to free memory allocated with new [].
Partial valgrind output follows:
==21267== Mismatched free() / delete / delete []
==21267==at 0x1B903D5D: operator delete[](void*) (vg_replace_malloc.c:161)
==21267==by 0x1BB0A9EC: