1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Fix possible leak due to usage of raw pointers in filesystem

This commit is contained in:
Ivan Savenko
2025-04-27 19:55:16 +03:00
parent 3547635c05
commit 4bafab9ad4
10 changed files with 65 additions and 64 deletions

View File

@@ -71,7 +71,7 @@ static std::string getModDirectory(const TModID & modName)
return "MODS/" + result;
}
static ISimpleResourceLoader * genModFilesystem(const std::string & modName, const JsonNode & conf)
static std::unique_ptr<ISimpleResourceLoader> genModFilesystem(const std::string & modName, const JsonNode & conf)
{
static const JsonNode defaultFS = genDefaultFS();
@@ -87,20 +87,20 @@ void CModHandler::loadModFilesystems()
const auto & activeMods = modManager->getActiveMods();
std::map<TModID, ISimpleResourceLoader *> modFilesystems;
std::map<TModID, std::unique_ptr<ISimpleResourceLoader>> modFilesystems;
for(const TModID & modName : activeMods)
modFilesystems[modName] = genModFilesystem(modName, getModInfo(modName).getFilesystemConfig());
for(const TModID & modName : activeMods)
if (modName != "core") // virtual mod 'core' has no filesystem on its own - shared with base install
CResourceHandler::addFilesystem("data", modName, modFilesystems[modName]);
if (settings["mods"]["validation"].String() == "full")
checkModFilesystemsConflicts(modFilesystems);
for(const TModID & modName : activeMods)
if (modName != "core") // virtual mod 'core' has no filesystem on its own - shared with base install
CResourceHandler::addFilesystem("data", modName, std::move(modFilesystems[modName]));
}
void CModHandler::checkModFilesystemsConflicts(const std::map<TModID, ISimpleResourceLoader *> & modFilesystems)
void CModHandler::checkModFilesystemsConflicts(const std::map<TModID, std::unique_ptr<ISimpleResourceLoader>> & modFilesystems)
{
for(const auto & [leftName, leftFilesystem] : modFilesystems)
{