widening a bit smart pointers usage considering xml data.

This commit is contained in:
David Carlier 2022-03-12 07:14:43 +00:00
parent 18018a5cc1
commit 9fb568eaa7
4 changed files with 6 additions and 18 deletions

View File

@ -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<XMLNode>(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
// ----------------------------------------------------------------------------

View File

@ -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<XMLNode>(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()

View File

@ -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<XMLNode>(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 configFileVersion<SUPPORTED_CONFIG_VERSION
@ -708,7 +706,7 @@ bool UserConfig::loadConfig()
// you want them automatically read from the config file)
for (unsigned i = 0; i < all_params.size(); i++)
{
all_params[i]->findYourDataInAChildOf(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

View File

@ -77,7 +77,7 @@ EasterEggHunt::~EasterEggHunt()
*/
void EasterEggHunt::readData(const std::string &filename)
{
XMLNode *easter = file_manager->createXMLTree(filename);
auto easter = std::unique_ptr<XMLNode>(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 <num_nodes
delete easter;
WorldStatus::setClockMode(CLOCK_CHRONO);
} // readEasterEggInfo