mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[11987] Fix possible memory leak in .gameobject add command
Thanks to Kid10 for pointing Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
parent
744995d27c
commit
0645d10286
2 changed files with 14 additions and 16 deletions
|
|
@ -1057,11 +1057,10 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
|
|||
if (!ExtractOptInt32(&args, spawntimeSecs, 0))
|
||||
return false;
|
||||
|
||||
const GameObjectInfo *gInfo = ObjectMgr::GetGameObjectInfo(id);
|
||||
|
||||
const GameObjectInfo* gInfo = ObjectMgr::GetGameObjectInfo(id);
|
||||
if (!gInfo)
|
||||
{
|
||||
PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
|
||||
PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1069,20 +1068,18 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
|
|||
if (gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId))
|
||||
{
|
||||
// report to DB errors log as in loading case
|
||||
sLog.outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.",id, gInfo->type, gInfo->displayId);
|
||||
PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA,id);
|
||||
sLog.outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", id, gInfo->type, gInfo->displayId);
|
||||
PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, id);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Player *chr = m_session->GetPlayer();
|
||||
float x = float(chr->GetPositionX());
|
||||
float y = float(chr->GetPositionY());
|
||||
float z = float(chr->GetPositionZ());
|
||||
float o = float(chr->GetOrientation());
|
||||
Map *map = chr->GetMap();
|
||||
|
||||
GameObject* pGameObj = new GameObject;
|
||||
Player* plr = m_session->GetPlayer();
|
||||
float x = float(plr->GetPositionX());
|
||||
float y = float(plr->GetPositionY());
|
||||
float z = float(plr->GetPositionZ());
|
||||
float o = float(plr->GetOrientation());
|
||||
Map* map = plr->GetMap();
|
||||
|
||||
// used guids from specially reserved range (can be 0 if no free values)
|
||||
uint32 db_lowGUID = sObjectMgr.GenerateStaticGameObjectLowGuid();
|
||||
|
|
@ -1093,7 +1090,8 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o))
|
||||
GameObject* pGameObj = new GameObject;
|
||||
if (!pGameObj->Create(db_lowGUID, gInfo->id, map, plr->GetPhaseMaskForSpawn(), x, y, z, o))
|
||||
{
|
||||
delete pGameObj;
|
||||
return false;
|
||||
|
|
@ -1103,7 +1101,7 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
|
|||
pGameObj->SetRespawnTime(spawntimeSecs);
|
||||
|
||||
// fill the gameobject data and save to the db
|
||||
pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()),chr->GetPhaseMaskForSpawn());
|
||||
pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), plr->GetPhaseMaskForSpawn());
|
||||
|
||||
// this will generate a new guid if the object is in an instance
|
||||
if (!pGameObj->LoadFromDB(db_lowGUID, map))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue