Core/Channels: Fixed a memory leak when loading a custom chat channel using AllowTwoSide.Interaction.Channel when both factions already had a channel with the same name (#32027)

(cherry picked from TrinityCore 05d99fde25f350d39f3bbabf4b97beeabfe817ab)
This commit is contained in:
Karrz1
2026-10-27 15:04:15 +00:00
parent 91d49b230f
commit d4e75e9bd4
+14 -7
View File
@@ -83,7 +83,7 @@ ChannelMgr::~ChannelMgr()
if (!Utf8toWStr(dbName, channelName))
{
TC_LOG_ERROR("server.loading", "Failed to load custom chat channel '{}' from database - invalid utf8 sequence? Deleted.", dbName);
toDelete.push_back({ dbName, team });
toDelete.emplace_back(std::move(dbName), team);
continue;
}
@@ -91,24 +91,31 @@ ChannelMgr::~ChannelMgr()
if (!mgr)
{
TC_LOG_ERROR("server.loading", "Failed to load custom chat channel '{}' from database - invalid team {}. Deleted.", dbName, team);
toDelete.push_back({ dbName, team });
toDelete.emplace_back(std::move(dbName), team);
continue;
}
Channel* channel = new Channel(mgr->CreateCustomChannelGuid(), dbName, team, dbBanned);
auto [itr, isNew] = mgr->_customChannels.try_emplace(std::move(channelName));
if (!isNew)
{
// with CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL both teams share the same manager, so channels with the same name from each team collide
TC_LOG_ERROR("server.loading", "Failed to load custom chat channel '{}' (team {}) from database - a channel with the same name is already loaded. Skipped.", dbName, team);
continue;
}
Channel* channel = itr->second = new Channel(mgr->CreateCustomChannelGuid(), dbName, team, dbBanned);
channel->SetAnnounce(dbAnnounce);
channel->SetOwnership(dbOwnership);
channel->SetPassword(dbPass);
mgr->_customChannels.emplace(channelName, channel);
++count;
} while (result->NextRow());
for (std::pair<std::string, uint32> const& pair : toDelete)
for (auto const& [dbName, team] : toDelete)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHANNEL);
stmt->setString(0, pair.first);
stmt->setUInt32(1, pair.second);
stmt->setString(0, dbName);
stmt->setUInt32(1, team);
CharacterDatabase.Execute(stmt);
}