mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-25 11:21:58 +01:00
Implement QueryResult_AutoPtr type which is ACE's reference counted auto_ptr(ACE_Refcounted_Auto_Ptr) for QueryResult pointers.
Use this auto_ptr for every DB queries(except QueryNamedResult yet). This patch guarantees NO memory leaks from QueryResult pointers. Thanks to raczman for the idea and for the helping to make this patch. --HG-- branch : trunk
This commit is contained in:
@@ -1457,10 +1457,9 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args)
|
||||
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
|
||||
if (gmRealmID == -1)
|
||||
{
|
||||
QueryResult *result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
|
||||
if (result)
|
||||
{
|
||||
delete result;
|
||||
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
|
||||
SetSentErrorMessage(true);
|
||||
return false;
|
||||
@@ -2620,7 +2619,7 @@ bool ChatHandler::HandleAddItemCommand(const char *args)
|
||||
{
|
||||
std::string itemName = citemName+1;
|
||||
WorldDatabase.escape_string(itemName);
|
||||
QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
|
||||
QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
|
||||
@@ -2628,7 +2627,6 @@ bool ChatHandler::HandleAddItemCommand(const char *args)
|
||||
return false;
|
||||
}
|
||||
itemId = result->Fetch()->GetUInt16();
|
||||
delete result;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
@@ -2811,16 +2809,13 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
if(count < 0)
|
||||
return false;
|
||||
|
||||
QueryResult *result;
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
// inventory case
|
||||
uint32 inv_count = 0;
|
||||
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
|
||||
if(result)
|
||||
{
|
||||
inv_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
result=CharacterDatabase.PQuery(
|
||||
// 0 1 2 3 4 5
|
||||
@@ -2857,8 +2852,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
|
||||
int64 res_count = result->GetRowCount();
|
||||
|
||||
delete result;
|
||||
|
||||
if(count > res_count)
|
||||
count-=res_count;
|
||||
else if(count)
|
||||
@@ -2869,10 +2862,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
uint32 mail_count = 0;
|
||||
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
|
||||
if(result)
|
||||
{
|
||||
mail_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
if(count > 0)
|
||||
{
|
||||
@@ -2884,7 +2874,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
item_id,uint32(count));
|
||||
}
|
||||
else
|
||||
result = NULL;
|
||||
result = QueryResult_AutoPtr(NULL);
|
||||
|
||||
if(result)
|
||||
{
|
||||
@@ -2907,8 +2897,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
|
||||
int64 res_count = result->GetRowCount();
|
||||
|
||||
delete result;
|
||||
|
||||
if(count > res_count)
|
||||
count-=res_count;
|
||||
else if(count)
|
||||
@@ -2919,10 +2907,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
uint32 auc_count = 0;
|
||||
result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
|
||||
if(result)
|
||||
{
|
||||
auc_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
if(count > 0)
|
||||
{
|
||||
@@ -2933,7 +2918,7 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
item_id,uint32(count));
|
||||
}
|
||||
else
|
||||
result = NULL;
|
||||
result = QueryResult_AutoPtr(NULL);
|
||||
|
||||
if(result)
|
||||
{
|
||||
@@ -2949,18 +2934,13 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
|
||||
PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
|
||||
} while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
}
|
||||
|
||||
// guild bank case
|
||||
uint32 guild_count = 0;
|
||||
result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
|
||||
if(result)
|
||||
{
|
||||
guild_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
result=CharacterDatabase.PQuery(
|
||||
// 0 1 2
|
||||
@@ -2984,8 +2964,6 @@ bool ChatHandler::HandleListItemCommand(const char *args)
|
||||
|
||||
int64 res_count = result->GetRowCount();
|
||||
|
||||
delete result;
|
||||
|
||||
if(count > res_count)
|
||||
count-=res_count;
|
||||
else if(count)
|
||||
@@ -3036,15 +3014,12 @@ bool ChatHandler::HandleListObjectCommand(const char *args)
|
||||
if(count < 0)
|
||||
return false;
|
||||
|
||||
QueryResult *result;
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
uint32 obj_count = 0;
|
||||
result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
|
||||
if(result)
|
||||
{
|
||||
obj_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
if(m_session)
|
||||
{
|
||||
@@ -3072,8 +3047,6 @@ bool ChatHandler::HandleListObjectCommand(const char *args)
|
||||
else
|
||||
PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
|
||||
} while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
|
||||
@@ -3171,15 +3144,12 @@ bool ChatHandler::HandleListCreatureCommand(const char *args)
|
||||
if(count < 0)
|
||||
return false;
|
||||
|
||||
QueryResult *result;
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
uint32 cr_count = 0;
|
||||
result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
|
||||
if(result)
|
||||
{
|
||||
cr_count = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
}
|
||||
|
||||
if(m_session)
|
||||
{
|
||||
@@ -3207,8 +3177,6 @@ bool ChatHandler::HandleListCreatureCommand(const char *args)
|
||||
else
|
||||
PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
|
||||
} while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
}
|
||||
|
||||
PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
|
||||
@@ -5932,7 +5900,7 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args)
|
||||
|
||||
bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
|
||||
{
|
||||
QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
|
||||
if(!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
|
||||
@@ -5954,7 +5922,6 @@ bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
|
||||
fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
|
||||
}while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5973,7 +5940,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
|
||||
std::string IP = cIP;
|
||||
|
||||
loginDatabase.escape_string(IP);
|
||||
QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
|
||||
if(!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOIP);
|
||||
@@ -5985,7 +5952,7 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
|
||||
PSendSysMessage(LANG_BANINFO_IPENTRY,
|
||||
fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(),
|
||||
permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
|
||||
delete result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5999,7 +5966,7 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args)
|
||||
|
||||
std::string filter = cFilter;
|
||||
loginDatabase.escape_string(filter);
|
||||
QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
|
||||
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_NOCHARACTER);
|
||||
@@ -6017,7 +5984,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args)
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
loginDatabase.escape_string(filter);
|
||||
|
||||
QueryResult* result;
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
if(filter.empty())
|
||||
{
|
||||
@@ -6040,7 +6007,7 @@ bool ChatHandler::HandleBanListAccountCommand(const char *args)
|
||||
return HandleBanListHelper(result);
|
||||
}
|
||||
|
||||
bool ChatHandler::HandleBanListHelper(QueryResult* result)
|
||||
bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
|
||||
|
||||
@@ -6052,12 +6019,11 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
|
||||
Field* fields = result->Fetch();
|
||||
uint32 accountid = fields[0].GetUInt32();
|
||||
|
||||
QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
|
||||
QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
|
||||
if(banresult)
|
||||
{
|
||||
Field* fields2 = banresult->Fetch();
|
||||
PSendSysMessage("%s",fields2[0].GetString());
|
||||
delete banresult;
|
||||
}
|
||||
} while (result->NextRow());
|
||||
}
|
||||
@@ -6083,7 +6049,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
|
||||
accmgr.GetName (account_id,account_name);
|
||||
|
||||
// No SQL injection. id is uint32.
|
||||
QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
|
||||
QueryResult_AutoPtr banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
|
||||
if (banInfo)
|
||||
{
|
||||
Field *fields2 = banInfo->Fetch();
|
||||
@@ -6108,13 +6074,10 @@ bool ChatHandler::HandleBanListHelper(QueryResult* result)
|
||||
fields2[2].GetString(),fields2[3].GetString());
|
||||
}
|
||||
}while ( banInfo->NextRow() );
|
||||
delete banInfo;
|
||||
}
|
||||
}while( result->NextRow() );
|
||||
SendSysMessage("===============================================================================");
|
||||
}
|
||||
|
||||
delete result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6126,7 +6089,7 @@ bool ChatHandler::HandleBanListIPCommand(const char *args)
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
loginDatabase.escape_string(filter);
|
||||
|
||||
QueryResult* result;
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
if(filter.empty())
|
||||
{
|
||||
@@ -6188,7 +6151,6 @@ bool ChatHandler::HandleBanListIPCommand(const char *args)
|
||||
SendSysMessage("===============================================================================");
|
||||
}
|
||||
|
||||
delete result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6892,7 +6854,7 @@ bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
|
||||
bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
|
||||
{
|
||||
///- Get the accounts with GM Level >0
|
||||
QueryResult *result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
|
||||
QueryResult_AutoPtr result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
|
||||
if(result)
|
||||
{
|
||||
SendSysMessage(LANG_GMLIST);
|
||||
@@ -6908,7 +6870,6 @@ bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
|
||||
}while( result->NextRow() );
|
||||
|
||||
PSendSysMessage("========================");
|
||||
delete result;
|
||||
}
|
||||
else
|
||||
PSendSysMessage(LANG_GMLIST_EMPTY);
|
||||
@@ -7396,7 +7357,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
|
||||
if (TargetName)
|
||||
{
|
||||
//check for offline players
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str());
|
||||
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.guid FROM characters WHERE characters.name = '%s'",name.c_str());
|
||||
if (!result)
|
||||
{
|
||||
SendSysMessage(LANG_COMMAND_FREEZE_WRONG);
|
||||
@@ -7405,7 +7366,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
|
||||
//if player found: delete his freeze aura
|
||||
Field *fields=result->Fetch();
|
||||
uint64 pguid = fields[0].GetUInt64();
|
||||
delete result;
|
||||
|
||||
CharacterDatabase.PQuery("DELETE FROM character_aura WHERE character_aura.spell = 9454 AND character_aura.guid = '%u'",pguid);
|
||||
PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str());
|
||||
return true;
|
||||
@@ -7423,7 +7384,7 @@ bool ChatHandler::HandleUnFreezeCommand(const char *args)
|
||||
bool ChatHandler::HandleListFreezeCommand(const char *args)
|
||||
{
|
||||
//Get names from DB
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454");
|
||||
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT characters.name FROM characters LEFT JOIN character_aura ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454");
|
||||
if (!result)
|
||||
{
|
||||
SendSysMessage(LANG_COMMAND_NO_FROZEN_PLAYERS);
|
||||
@@ -7440,7 +7401,6 @@ bool ChatHandler::HandleListFreezeCommand(const char *args)
|
||||
PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str());
|
||||
} while (result->NextRow());
|
||||
|
||||
delete result;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user