From bad6812b2b28d30a9b7cf8a5aa5d95dc2f3d1759 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Fri, 13 Oct 2023 12:23:32 +0200 Subject: [PATCH] replaced raw pointers by smart pointers for any2many.cpp. --- src/any2many.cpp | 48 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/src/any2many.cpp b/src/any2many.cpp index 1cb35a26..6cf92f61 100644 --- a/src/any2many.cpp +++ b/src/any2many.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -493,49 +494,31 @@ int main(int argc, char *argv[]) // read startup file char startup_path_name[128]; - TSAXParser *saxParser = new TSAXParser(); - PStartupHandler *startupHandler = new PStartupHandler(); + std::unique_ptr saxParser = std::unique_ptr(new TSAXParser()); + std::unique_ptr startupHandler = std::unique_ptr(new PStartupHandler()); if (!startupHandler->StartupFileFound()) { std::cerr << std::endl << ">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data(); std::cerr << std::endl; - // clean up - if (saxParser) { - delete saxParser; - saxParser = nullptr; - } - if (startupHandler) { - delete startupHandler; - startupHandler = nullptr; - } } else { strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); - saxParser->ConnectToHandler("PStartupHandler", startupHandler); + saxParser->ConnectToHandler("PStartupHandler", startupHandler.get()); //status = saxParser->ParseFile(startup_path_name); // parsing the file as above seems to lead to problems in certain environments; // use the parseXmlFile function instead (see PStartupHandler.cpp for the definition) - status = parseXmlFile(saxParser, startup_path_name); + status = parseXmlFile(saxParser.get(), startup_path_name); // check for parse errors if (status) { // error std::cerr << std::endl << ">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed."; std::cerr << std::endl; - // clean up - if (saxParser) { - delete saxParser; - saxParser = nullptr; - } - if (startupHandler) { - delete startupHandler; - startupHandler = nullptr; - } } } // read all the necessary runs (raw data) - PRunDataHandler *dataHandler; + std::unique_ptr dataHandler; if (startupHandler) - dataHandler = new PRunDataHandler(&info, startupHandler->GetDataPathList()); + dataHandler = std::unique_ptr(new PRunDataHandler(&info, startupHandler->GetDataPathList())); else - dataHandler = new PRunDataHandler(&info); + dataHandler = std::unique_ptr(new PRunDataHandler(&info)); // read and convert all data dataHandler->ConvertData(); @@ -546,21 +529,6 @@ int main(int argc, char *argv[]) std::cerr << std::endl << ">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl; } - // clean up - info.runList.clear(); - if (saxParser) { - delete saxParser; - saxParser = nullptr; - } - if (startupHandler) { - delete startupHandler; - startupHandler = nullptr; - } - if (dataHandler) { - delete dataHandler; - dataHandler = nullptr; - } - return PMUSR_SUCCESS; }