Core/AuctionHouse: Fixed possible use after free when auctions are removed with offline buyers

Port From (https://github.com/TrinityCore/TrinityCore/commit/1f73cf9f19679f5b888f9df475b94c9405f2d746)
This commit is contained in:
hondacrx
2024-03-12 22:16:39 -04:00
parent 7e7b8ed58b
commit 5b938c1a3e
2 changed files with 41 additions and 36 deletions
+10 -5
View File
@@ -785,20 +785,25 @@ namespace Game
{ {
SendAuctionExpired(auction, trans); SendAuctionExpired(auction, trans);
Global.ScriptMgr.OnAuctionExpire(this, auction); Global.ScriptMgr.OnAuctionExpire(this, auction);
RemoveAuction(trans, auction);
} }
///- Or perform the transaction ///- Or perform the transaction
else else
{ {
// Copy data before freeing AuctionPosting in auctionHouse->RemoveAuction
// Because auctionHouse->SendAuctionWon can unload items if bidder is offline
// we need to RemoveAuction before sending mails
AuctionPosting copy = auction;
RemoveAuction(trans, auction);
//we should send an "item sold" message if the seller is online //we should send an "item sold" message if the seller is online
//we send the item to the winner //we send the item to the winner
//we send the money to the seller //we send the money to the seller
SendAuctionWon(auction, null, trans); SendAuctionSold(copy, null, trans);
SendAuctionSold(auction, null, trans); SendAuctionWon(copy, null, trans);
Global.ScriptMgr.OnAuctionSuccessful(this, auction); Global.ScriptMgr.OnAuctionSuccessful(this, auction);
} }
///- In any case clear the auction
RemoveAuction(trans, auction);
} }
// Run DB changes // Run DB changes
+1 -1
View File
@@ -390,8 +390,8 @@ namespace Game
if (canBuyout && placeBid.BidAmount == auction.BuyoutOrUnitPrice) if (canBuyout && placeBid.BidAmount == auction.BuyoutOrUnitPrice)
{ {
// buyout // buyout
auctionHouse.SendAuctionWon(auction, player, trans);
auctionHouse.SendAuctionSold(auction, null, trans); auctionHouse.SendAuctionSold(auction, null, trans);
auctionHouse.SendAuctionWon(auction, player, trans);
auctionHouse.RemoveAuction(trans, auction); auctionHouse.RemoveAuction(trans, auction);
} }