Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: depotchest memory leak #4510

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5681,7 +5681,7 @@ std::vector<Item*> Game::getMarketItemList(uint16_t wareId, uint16_t sufficientC

for (const auto& chest : player.depotChests) {
if (!chest.second->empty()) {
containers.push_front(chest.second);
containers.push_front(chest.second.get());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate)
{
auto it = depotChests.find(depotId);
if (it != depotChests.end()) {
return it->second;
return it->second.get();
}

if (!autoCreate) {
Expand All @@ -841,9 +841,9 @@ DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate)
return nullptr;
}

it = depotChests.emplace(depotId, new DepotChest(depotItemId)).first;
it = depotChests.emplace(depotId, std::make_shared<DepotChest>(depotItemId)).first;
it->second->setMaxDepotItems(getMaxDepotItems());
return it->second;
return it->second.get();
}

DepotLocker& Player::getDepotLocker()
Expand Down Expand Up @@ -3218,7 +3218,7 @@ void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int
bool isOwner = false;

for (const auto& it : depotChests) {
if (it.second == depotChest) {
if (it.second.get() == depotChest) {
isOwner = true;
onSendContainer(container);
}
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ class Player final : public Creature, public Cylinder
std::unordered_set<uint32_t> VIPList;

std::map<uint8_t, OpenContainer> openContainers;
std::map<uint32_t, DepotChest*> depotChests;
std::map<uint32_t, std::shared_ptr<DepotChest>> depotChests;

std::vector<OutfitEntry> outfits;
GuildWarVector guildWarVector;
Expand Down
2 changes: 1 addition & 1 deletion src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ void ProtocolGame::sendMarketEnter()

for (const auto& chest : player->depotChests) {
if (!chest.second->empty()) {
containerList.push_front(chest.second);
containerList.push_front(chest.second.get());
}
}

Expand Down