Skip to content

Commit

Permalink
[11987] Fix possible memory leak in .gameobject add command
Browse files Browse the repository at this point in the history
Thanks to Kid10 for pointing

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
  • Loading branch information
Schmoozerd committed May 5, 2012
1 parent b6db6c7 commit 74e9f84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions src/game/Level2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,32 +1057,29 @@ 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;
}

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();
Expand All @@ -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;
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11986"
#define REVISION_NR "11987"
#endif // __REVISION_NR_H__

0 comments on commit 74e9f84

Please sign in to comment.