From 707eadddbc91fea0eb0f234e867b87c9c6ef8d20 Mon Sep 17 00:00:00 2001 From: Francois Gygi Date: Wed, 1 Aug 2018 15:53:20 -0700 Subject: [PATCH] Use StrX in XML handler classes to avoid mem leaks --- src/AtomSetHandler.C | 16 ++++++++-------- src/SampleHandler.C | 4 ++-- src/SpeciesHandler.C | 10 ++++------ src/WavefunctionHandler.C | 32 ++++++++++++++++---------------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/AtomSetHandler.C b/src/AtomSetHandler.C index f173382..199fd2b 100644 --- a/src/AtomSetHandler.C +++ b/src/AtomSetHandler.C @@ -42,7 +42,7 @@ void AtomSetHandler::startElement(const XMLCh* const uri, const Attributes& attributes) { // cout << " AtomSetHandler::startElement " << StrX(qname) << endl; - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); // consider only elements that are dealt with directly by AtomSetHandler // i.e. "atom". The "species" element is delegated to a SpeciesHandler @@ -52,8 +52,8 @@ void AtomSetHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "a") { @@ -79,7 +79,7 @@ void AtomSetHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); if ( attrname == "name") { current_atom_name = StrX(attributes.getValue(index)).localForm(); @@ -96,7 +96,7 @@ void AtomSetHandler::startElement(const XMLCh* const uri, void AtomSetHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, string& content) { - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); // cout << " AtomSetHandler::endElement " << locname << endl; istringstream stst(content); if ( locname == "unit_cell") @@ -146,14 +146,14 @@ StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri, // If it can, return a pointer to the StructureHandler, otherwise return 0 // cout << " AtomSetHandler::startSubHandler " << StrX(qname) << endl; - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); if ( locname == "species") { // check for species attributes unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); if ( attrname == "name") { current_species_name = StrX(attributes.getValue(index)).localForm(); @@ -175,7 +175,7 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const last) { - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); // cout << " AtomSetHandler::endSubHandler " << locname << endl; if ( locname == "species" ) { diff --git a/src/SampleHandler.C b/src/SampleHandler.C index 8e18156..9fd45ad 100644 --- a/src/SampleHandler.C +++ b/src/SampleHandler.C @@ -46,7 +46,7 @@ void SampleHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, string& content) { // istringstream stst(st); - // string locname(XMLString::transcode(localname)); + // string locname = StrX(localname).localForm(); // cout << " SampleHandler::endElement " << locname << endl; } @@ -59,7 +59,7 @@ StructureHandler* SampleHandler::startSubHandler(const XMLCh* const uri, // If it can, return a pointer to the StructureHandler, otherwise return 0 // cout << " SampleHandler::startSubHandler " << StrX(qname) << endl; - string qnm = XMLString::transcode(qname); + string qnm = StrX(qname).localForm(); if ( qnm == "atomset" ) { return new AtomSetHandler(s_.atoms); diff --git a/src/SpeciesHandler.C b/src/SpeciesHandler.C index a10d6c4..67259c8 100644 --- a/src/SpeciesHandler.C +++ b/src/SpeciesHandler.C @@ -39,7 +39,7 @@ void SpeciesHandler::read(const Attributes& attributes) unsigned int len = attributes.getLength(); for ( unsigned int index = 0; index < len; index++ ) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); if ( attrname == "l" ) { current_l = atoi(StrX(attributes.getValue(index)).localForm()); @@ -84,7 +84,7 @@ void SpeciesHandler::startElement(const XMLCh* const uri, { // cout << " SpeciesHandler::startElement " << StrX(qname) << endl; - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); if ( locname == "species" ) { @@ -92,7 +92,7 @@ void SpeciesHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for ( unsigned int index = 0; index < len; index++ ) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); if ( attrname == "name" ) { current_name = StrX(attributes.getValue(index)).localForm(); @@ -135,10 +135,8 @@ void SpeciesHandler::startElement(const XMLCh* const uri, void SpeciesHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, string& content) { - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); istringstream stst(content); -// cout << " SpeciesHandler::endElement " << StrX(qname) << " content=" -// << string(content,0,20) << endl; if ( locname == "description" ) { diff --git a/src/WavefunctionHandler.C b/src/WavefunctionHandler.C index 8fd0de0..1f33cdb 100644 --- a/src/WavefunctionHandler.C +++ b/src/WavefunctionHandler.C @@ -65,7 +65,7 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, { bool onpe0 = wf_.context().onpe0(); // cout << " WavefunctionHandler::startElement " << StrX(qname) << endl; - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); int nspin=1, nel=0, nempty=0; @@ -76,7 +76,7 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); if ( attrname == "ecut") { ecut = atof(StrX(attributes.getValue(index)).localForm()); @@ -116,8 +116,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "a") { @@ -143,8 +143,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "a") { @@ -171,8 +171,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, string dmat_form; for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "form") { @@ -195,8 +195,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "nx") { @@ -240,8 +240,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "kpoint") { @@ -302,8 +302,8 @@ void WavefunctionHandler::startElement(const XMLCh* const uri, unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { - string attrname(XMLString::transcode(attributes.getLocalName(index))); - string attrval(XMLString::transcode(attributes.getValue(index))); + string attrname = StrX(attributes.getLocalName(index)).localForm(); + string attrval = StrX(attributes.getValue(index)).localForm(); istringstream stst(attrval); if ( attrname == "nx") { @@ -338,7 +338,7 @@ void WavefunctionHandler::endElement(const XMLCh* const uri, { const Context& ctxt = wf_.context(); bool onpe0 = ctxt.onpe0(); - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); //cout << " WavefunctionHandler::endElement " << locname << endl; if ( locname == "density_matrix") { @@ -495,7 +495,7 @@ void WavefunctionHandler::endSubHandler(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const last) { - string locname(XMLString::transcode(localname)); + string locname = StrX(localname).localForm(); //cout << " WavefunctionHandler::endSubHandler " << locname << endl; delete last; } -- libgit2 0.26.0