diff --git a/src/addons/addons_manager.cpp b/src/addons/addons_manager.cpp index d469c72ac..c46356d21 100644 --- a/src/addons/addons_manager.cpp +++ b/src/addons/addons_manager.cpp @@ -449,7 +449,7 @@ void AddonsManager::loadInstalledAddons() Log::info("addons", "Loading an xml file for installed addons: %s.", m_file_installed.c_str()); } - const XMLNode *xml = file_manager->createXMLTree(m_file_installed); + auto xml = std::unique_ptr(file_manager->createXMLTree(m_file_installed)); if(!xml) return; @@ -463,8 +463,6 @@ void AddonsManager::loadInstalledAddons() m_addons_list.getData().push_back(addon); } } // for i <= xml->getNumNodes() - - delete xml; } // loadInstalledAddons // ---------------------------------------------------------------------------- diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index b43e75cd5..e211664d4 100644 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -42,14 +42,13 @@ MusicInformation *MusicInformation::create(const std::string &filename) { assert(filename.size() > 0); - XMLNode* root = file_manager->createXMLTree(filename); + auto root = std::unique_ptr(file_manager->createXMLTree(filename)); if (!root) return NULL; if(root->getName()!="music") { Log::error("MusicInformation", "Music file '%s' does not contain music node.\n", filename.c_str()); - delete root; return NULL; } std::string s; @@ -61,11 +60,9 @@ MusicInformation *MusicInformation::create(const std::string &filename) "One of 'title' or 'file' attribute " "is missing in the music XML file '%s'!\n", filename.c_str()); - delete root; return NULL; } - MusicInformation *mi = new MusicInformation(root, filename); - delete root; + MusicInformation *mi = new MusicInformation(root.get(), filename); return mi; } // create() diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index ac6164a0c..37f1c0e2a 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -669,12 +669,11 @@ UserConfig::~UserConfig() bool UserConfig::loadConfig() { const std::string filename = file_manager->getUserConfigFile(m_filename); - XMLNode* root = file_manager->createXMLTree(filename); + auto root = std::unique_ptr(file_manager->createXMLTree(filename)); if(!root || root->getName() != "stkconfig") { Log::info("UserConfig", "Could not read user config file '%s'. A new file will be created.", filename.c_str()); - if(root) delete root; // Create a default config file - just in case that stk crashes later // there is a config file that can be modified (to e.g. disable // shaders) @@ -699,7 +698,6 @@ bool UserConfig::loadConfig() GUIEngine::showMessage(_("Your config file was too old, so it was deleted and a new one will be created."), 10.0f); Log::info("UserConfig", "Your config file was too old, so it was deleted and a new one will be created."); - delete root; return false; } // if configFileVersionfindYourDataInAChildOf(root); + all_params[i]->findYourDataInAChildOf(root.get()); } @@ -722,7 +720,6 @@ bool UserConfig::loadConfig() UserConfigParams::m_saved_grand_prix_list.push_back( new SavedGrandPrix( saved_gps[i]) ); } - delete root; return true; } // loadConfig diff --git a/src/modes/easter_egg_hunt.cpp b/src/modes/easter_egg_hunt.cpp index ca3da5015..7d74f0a37 100644 --- a/src/modes/easter_egg_hunt.cpp +++ b/src/modes/easter_egg_hunt.cpp @@ -77,7 +77,7 @@ EasterEggHunt::~EasterEggHunt() */ void EasterEggHunt::readData(const std::string &filename) { - XMLNode *easter = file_manager->createXMLTree(filename); + auto easter = std::unique_ptr(file_manager->createXMLTree(filename)); if(!easter) return; @@ -85,7 +85,6 @@ void EasterEggHunt::readData(const std::string &filename) { Log::error("[EasterEggHunt]", "Can't load easter egg file '%s' - no EasterEggHunt element.", filename.c_str()); - delete easter; return; } @@ -111,7 +110,6 @@ void EasterEggHunt::readData(const std::string &filename) if(!data) { - delete easter; return; } m_number_of_eggs = 0; @@ -129,8 +127,6 @@ void EasterEggHunt::readData(const std::string &filename) m_number_of_eggs++; } // for i