From 73b6c869d1ebd478fce2392c421ab9074fffb4c0 Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Mon, 10 Feb 2014 16:26:48 +0000 Subject: [PATCH 1/6] Use AutoPtr for NodeLists not released re #8485 Signed-off-by: Karl Palmen --- Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp | 6 +++--- Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp | 2 +- Code/Mantid/Framework/DataHandling/src/LoadMask.cpp | 2 +- Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp index 15bd4a570777..bf4b57af2a95 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp @@ -181,7 +181,7 @@ MatrixWorkspace_sptr LoadCanSAS1D::loadEntry(Poco::XML::Node * const workspaceDa check(workspaceElem, ""); runName = workspaceElem->getAttribute("name"); - NodeList* runs = workspaceElem->getElementsByTagName("Run"); + Poco::AutoPtr runs = workspaceElem->getElementsByTagName("Run"); if ( runs->length() != 1 ) { throw Exception::NotImplementedError("s containing multiple runs, or no runs, are not currently supported"); @@ -336,12 +336,12 @@ void LoadCanSAS1D::createLogs(const Poco::XML::Element * const sasEntry, API::Ma Element * runText = sasEntry->getChildElement("Run"); check(runText, "Run"); run.addLogData(new PropertyWithValue( - "run_number", runText->innerText())); + "run_number", runText->innerText())); Element * process = sasEntry->getChildElement("SASprocess"); if (process) { - NodeList* terms = process->getElementsByTagName("term"); + Poco::AutoPtr terms = process->getElementsByTagName("term"); for ( unsigned int i = 0; i < terms->length(); ++i ) { Node* term = terms->item(i); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp index 6e1f20d414b0..64a715dc0e22 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp @@ -147,7 +147,7 @@ MatrixWorkspace_sptr LoadCanSAS1D2::loadEntry(Poco::XML::Node * const workspaceD Element *workspaceElem = dynamic_cast(workspaceData); // check(workspaceElem, ""); // already done at LoadCanSAS1D::loadEntry - NodeList * sasTransList = workspaceElem->getElementsByTagName("SAStransmission_spectrum"); + Poco::AutoPtr sasTransList = workspaceElem->getElementsByTagName("SAStransmission_spectrum"); if (!sasTransList->length()){ //sasTransList->release(); g_log.warning() << "There is no transmission data for this file " << getPropertyValue("Filename") << std::endl; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadMask.cpp b/Code/Mantid/Framework/DataHandling/src/LoadMask.cpp index 88c3e3700725..3a804b5302d6 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadMask.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadMask.cpp @@ -515,7 +515,7 @@ namespace DataHandling throw std::runtime_error("Call LoadMask::initialize() before parseXML."); // 1. Parse and create a structure - NodeList* pNL_type = pRootElem->getElementsByTagName("type"); + Poco::AutoPtr pNL_type = pRootElem->getElementsByTagName("type"); g_log.information() << "Node Size = " << pNL_type->length() << std::endl; Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT); diff --git a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp index e6147f766912..f5a61f2a37d5 100644 --- a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp @@ -84,7 +84,7 @@ std::string SNSDataArchive::getArchivePath(const std::set& filename if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) { std::string location; - Poco::XML::NodeList* pList = pDoc->getElementsByTagName("location"); + Poco::AutoPtr pList = pDoc->getElementsByTagName("location"); for(unsigned long i = 0 ; i < pList->length(); i++) { location = pList->item(i)->innerText(); From fe0de606cbe52f2120917d385e81f2148bf355ff Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Tue, 11 Feb 2014 14:38:51 +0000 Subject: [PATCH 2/6] Use AutoPtr for a Document re #8485 Signed-off-by: Karl Palmen --- Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp index f5a61f2a37d5..47458a5ef58e 100644 --- a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp @@ -20,11 +20,13 @@ #include #include #include +#include "Poco/DOM/AutoPtr.h" #include using Poco::Net::ConnectionRefusedException; using Poco::URI; +using namespace Poco::XML; namespace Mantid { @@ -75,7 +77,7 @@ std::string SNSDataArchive::getArchivePath(const std::set& filename // Create a DOM document from the response. Poco::XML::DOMParser parser; Poco::XML::InputSource source(rs); - Poco::XML::Document* pDoc = parser.parse(&source); + AutoPtr pDoc = parser.parse(&source); std::vector locations; From beba8036a8a10c1ebdd62f15d4d5748a42d9668c Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Tue, 11 Feb 2014 15:30:56 +0000 Subject: [PATCH 3/6] Tidy up code a little re #8485 Signed-off-by: Karl Palmen --- Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp index 47458a5ef58e..b9477033019a 100644 --- a/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SNSDataArchive.cpp @@ -26,7 +26,6 @@ using Poco::Net::ConnectionRefusedException; using Poco::URI; -using namespace Poco::XML; namespace Mantid { @@ -77,7 +76,7 @@ std::string SNSDataArchive::getArchivePath(const std::set& filename // Create a DOM document from the response. Poco::XML::DOMParser parser; Poco::XML::InputSource source(rs); - AutoPtr pDoc = parser.parse(&source); + Poco::AutoPtr pDoc = parser.parse(&source); std::vector locations; From 53614ab7c5289d0391082610bb72ad0111fd1062 Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Wed, 12 Feb 2014 16:30:44 +0000 Subject: [PATCH 4/6] Use AutoPtr in those cases where release() is used re #8485 Signed-off-by: Karl Palmen --- .../Framework/DataHandling/src/LoadCanSAS1D.cpp | 13 +++++-------- .../Framework/DataHandling/src/LoadCanSAS1D2.cpp | 3 +-- .../DataHandling/src/LoadPreNexusMonitors.cpp | 8 ++------ .../Framework/DataHandling/src/LoadSpice2D.cpp | 8 ++------ 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp index bf4b57af2a95..c1b8599d9c4c 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp @@ -25,6 +25,7 @@ If the file contains mulitple SASentry elements a workspace group will be create #include #include #include +#include #include //----------------------------------------------------------------------- @@ -80,7 +81,7 @@ int LoadCanSAS1D::confidence(Kernel::FileDescriptor & descriptor) const Poco::XML::InputSource src(is); // Set up the DOM parser and parse xml file DOMParser pParser; - Document* pDoc; + Poco::AutoPtr pDoc; try { pDoc = pParser.parse(&src); @@ -98,7 +99,6 @@ int LoadCanSAS1D::confidence(Kernel::FileDescriptor & descriptor) const confidence = 80; } } - pDoc->release(); }// end of inner scope return confidence; @@ -123,7 +123,7 @@ void LoadCanSAS1D::exec() const std::string fileName = getPropertyValue("Filename"); // Set up the DOM parser and parse xml file DOMParser pParser; - Document* pDoc; + Poco::AutoPtr pDoc; try { pDoc = pParser.parse(fileName); @@ -138,7 +138,7 @@ void LoadCanSAS1D::exec() throw Kernel::Exception::NotFoundError("No root element in CanSAS1D XML file", fileName); } // there can be multiple elements, each one contains a period which will go into a workspace group if there are more than one of them - NodeList* entryList = pRootElem->getElementsByTagName("SASentry"); + Poco::AutoPtr entryList = pRootElem->getElementsByTagName("SASentry"); size_t numEntries = entryList->length(); Workspace_sptr outputWork; MatrixWorkspace_sptr WS; @@ -164,8 +164,6 @@ void LoadCanSAS1D::exec() } outputWork = group; } - entryList->release(); - pDoc->release(); setProperty("OutputWorkspace", outputWork); } /** Load an individual "" element into a new workspace @@ -190,7 +188,7 @@ MatrixWorkspace_sptr LoadCanSAS1D::loadEntry(Poco::XML::Node * const workspaceDa Element* sasDataElem = workspaceElem->getChildElement("SASdata"); check(sasDataElem, ""); // getting number of Idata elements in the xml file - NodeList* idataElemList = sasDataElem->getElementsByTagName("Idata"); + Poco::AutoPtr idataElemList = sasDataElem->getElementsByTagName("Idata"); size_t nBins = idataElemList->length(); MatrixWorkspace_sptr dataWS = @@ -266,7 +264,6 @@ MatrixWorkspace_sptr LoadCanSAS1D::loadEntry(Poco::XML::Node * const workspaceDa // run load instrument runLoadInstrument(instname, dataWS); - idataElemList->release(); dataWS->getAxis(0)->setUnit("MomentumTransfer"); return dataWS; } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp index 64a715dc0e22..42e2737e35ac 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp @@ -148,8 +148,7 @@ MatrixWorkspace_sptr LoadCanSAS1D2::loadEntry(Poco::XML::Node * const workspaceD Element *workspaceElem = dynamic_cast(workspaceData); // check(workspaceElem, ""); // already done at LoadCanSAS1D::loadEntry Poco::AutoPtr sasTransList = workspaceElem->getElementsByTagName("SAStransmission_spectrum"); - if (!sasTransList->length()){ - //sasTransList->release(); + if (!sasTransList->length()){ g_log.warning() << "There is no transmission data for this file " << getPropertyValue("Filename") << std::endl; return main_out; } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadPreNexusMonitors.cpp b/Code/Mantid/Framework/DataHandling/src/LoadPreNexusMonitors.cpp index 6c64df15e3e1..bdcde21cb165 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadPreNexusMonitors.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadPreNexusMonitors.cpp @@ -142,7 +142,7 @@ void LoadPreNexusMonitors::exec() if (pNode->nodeName() == "DataList") { // Get a list of the child elements - Poco::XML::NodeList* pDataListChildren = pNode->childNodes(); + Poco::AutoPtr pDataListChildren = pNode->childNodes(); for (unsigned long i = 0; i < pDataListChildren->length(); ++i) { // We only care about monitors @@ -153,8 +153,6 @@ void LoadPreNexusMonitors::exec() monitorFilenames.push_back(element->getAttribute("name")); } } - // Release the NodeList - pDataListChildren->release(); } @@ -162,7 +160,7 @@ void LoadPreNexusMonitors::exec() if (pNode->nodeName() == "FileFormats") { // Get a list of the child elements - Poco::XML::NodeList* pDataListChildren = pNode->childNodes(); + Poco::AutoPtr pDataListChildren = pNode->childNodes(); for (unsigned long i = 0; i < pDataListChildren->length(); ++i) { // We only care about monitors @@ -173,8 +171,6 @@ void LoadPreNexusMonitors::exec() tchannels = boost::lexical_cast(dims); } } - // Release the NodeList - pDataListChildren->release(); } pNode = it.nextNode(); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp b/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp index 9572d81c7604..486c9b22299b 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp @@ -112,7 +112,7 @@ namespace Mantid Poco::XML::InputSource src(is); // Set up the DOM parser and parse xml file DOMParser pParser; - Document* pDoc; + Poco::AutoPtr pDoc; try { pDoc = pParser.parse(&src); @@ -130,7 +130,6 @@ namespace Mantid confidence = 80; } } - pDoc->release(); }// end of inner scope return confidence; @@ -179,7 +178,7 @@ namespace Mantid // Set up the DOM parser and parse xml file DOMParser pParser; - Document* pDoc; + Poco::AutoPtr pDoc; try { pDoc = pParser.parse(fileName); @@ -421,9 +420,6 @@ namespace Mantid g_log.error("Unable to successfully run MoveInstrumentComponent Child Algorithm"); g_log.error(e.what()); } - - // Release the XML document memory - pDoc->release(); } /** Run the Child Algorithm LoadInstrument (as for LoadRaw) From 72531ed4e4e9ed38035cb33182ea7e615b74e5d2 Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Tue, 18 Feb 2014 09:57:55 +0000 Subject: [PATCH 5/6] Make remaining fix in LoadCanSAS1D2.cpp re #8485 Signed-off-by: Karl Palmen --- Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp index 42e2737e35ac..a5914756d46d 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp @@ -163,7 +163,7 @@ MatrixWorkspace_sptr LoadCanSAS1D2::loadEntry(Poco::XML::Node * const workspaceD std::vector & group = (sasTrasElem->getAttribute("name") == "sample")? trans_gp : trans_can_gp; // getting number of Tdata elements in the xml file - NodeList* tdataElemList = sasTrasElem->getElementsByTagName("Tdata"); + Poco::AutoPtr tdataElemList = sasTrasElem->getElementsByTagName("Tdata"); size_t nBins = tdataElemList->length(); MatrixWorkspace_sptr dataWS = From db6a92bed99567573189a80bd565b6f0b7751136 Mon Sep 17 00:00:00 2001 From: Karl Palmen Date: Fri, 21 Feb 2014 12:47:40 +0000 Subject: [PATCH 6/6] Remove release statement re #8485 Signed-off-by: Karl Palmen --- Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp index a5914756d46d..48d74460d8a8 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D2.cpp @@ -221,7 +221,6 @@ MatrixWorkspace_sptr LoadCanSAS1D2::loadEntry(Poco::XML::Node * const workspaceD } runLoadInstrument(main_out->getInstrument()->getName(), dataWS); - tdataElemList->release(); dataWS->getAxis(0)->setUnit("Wavelength"); // add to group