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:
Anubisss
2010-01-23 14:45:58 +01:00
parent c784110d87
commit d9cb070215
76 changed files with 458 additions and 1108 deletions
+2 -6
View File
@@ -215,7 +215,7 @@ bool ChatHandler::HandleServerExitCommand(const char* /*args*/)
bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
{
///- Get the list of accounts ID logged to the realm
QueryResult *resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0");
QueryResult_AutoPtr resultDB = CharacterDatabase.Query("SELECT name,account FROM characters WHERE online > 0");
if (!resultDB)
{
SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
@@ -236,7 +236,7 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
QueryResult *resultLogin =
QueryResult_AutoPtr resultLogin =
loginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion "
"FROM account a "
"LEFT JOIN account_access aa "
@@ -247,16 +247,12 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
Field *fieldsLogin = resultLogin->Fetch();
PSendSysMessage(LANG_ACCOUNT_LIST_LINE,
fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsLogin[2].GetUInt32(),fieldsLogin[3].GetUInt32());
delete resultLogin;
}
else
PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
}while(resultDB->NextRow());
delete resultDB;
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
+3 -3
View File
@@ -135,9 +135,9 @@ public:
{
loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive");
delete WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
delete loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
loginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
+2 -4
View File
@@ -154,7 +154,7 @@ void RASocket::OnRead()
///- Escape the Login to allow quotes in names
loginDatabase.escape_string(login);
QueryResult* result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ());
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ());
///- If the user is not found, deny access
if(!result)
@@ -187,7 +187,6 @@ void RASocket::OnRead()
{
stage=LG;
}
delete result;
}
}
break;
@@ -204,13 +203,12 @@ void RASocket::OnRead()
loginDatabase.escape_string(login);
loginDatabase.escape_string(pw);
QueryResult *check = loginDatabase.PQuery(
QueryResult_AutoPtr check = loginDatabase.PQuery(
"SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT('%s',':','%s'))",
login.c_str(), login.c_str(), pw.c_str());
if(check)
{
delete check;
r=GetSocket();
stage=OK;
++iUsers;