diff options
| author | Anubisss <none@none> | 2010-01-23 14:45:58 +0100 |
|---|---|---|
| committer | Anubisss <none@none> | 2010-01-23 14:45:58 +0100 |
| commit | d9cb0702158fd045285f2c0a904cb31a45a3864a (patch) | |
| tree | cdc6a7c6a83c6eea603ae296a653fb9f04945aad /src/trinityrealm | |
| parent | c784110d87666579f18620a98e1e57118db4a9cf (diff) | |
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
Diffstat (limited to 'src/trinityrealm')
| -rw-r--r-- | src/trinityrealm/AuthSocket.cpp | 18 | ||||
| -rw-r--r-- | src/trinityrealm/Main.cpp | 2 | ||||
| -rw-r--r-- | src/trinityrealm/RealmList.cpp | 3 |
3 files changed, 7 insertions, 16 deletions
diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp index f9aa40af629..b5fe5f040c1 100644 --- a/src/trinityrealm/AuthSocket.cpp +++ b/src/trinityrealm/AuthSocket.cpp @@ -399,12 +399,11 @@ bool AuthSocket::_HandleLogonChallenge() std::string address = GetRemoteAddress(); loginDatabase.escape_string(address); - QueryResult *result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); if (result) { pkt << (uint8)REALM_AUTH_ACCOUNT_BANNED; sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!",GetRemoteAddress().c_str ()); - delete result; } else { @@ -446,7 +445,7 @@ bool AuthSocket::_HandleLogonChallenge() //set expired bans to inactive loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); ///- If the account is banned, reject the logon attempt - QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); + QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); if (banresult) { if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) @@ -459,8 +458,6 @@ bool AuthSocket::_HandleLogonChallenge() pkt << (uint8) REALM_AUTH_ACCOUNT_FREEZED; sLog.outBasic("[AuthChallenge] Temporarily banned account %s tries to login!",_login.c_str ()); } - - delete banresult; } else { @@ -535,7 +532,6 @@ bool AuthSocket::_HandleLogonChallenge() sLog.outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)); } } - delete result; } else //no account { @@ -737,7 +733,7 @@ bool AuthSocket::_HandleLogonProof() //Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP loginDatabase.PExecute("UPDATE account SET failed_logins = failed_logins + 1 WHERE username = '%s'",_safelogin.c_str()); - if (QueryResult *loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str())) + if (QueryResult_AutoPtr loginfail = loginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str())) { Field* fields = loginfail->Fetch(); uint32 failed_logins = fields[1].GetUInt32(); @@ -765,7 +761,6 @@ bool AuthSocket::_HandleLogonProof() current_ip.c_str(), WrongPassBanTime, _login.c_str(), failed_logins); } } - delete loginfail; } } } @@ -805,7 +800,7 @@ bool AuthSocket::_HandleReconnectChallenge() _login = (const char*)ch->I; _safelogin = _login; - QueryResult *result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ()); + QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ()); // Stop if the account is not found if (!result) @@ -817,7 +812,6 @@ bool AuthSocket::_HandleReconnectChallenge() Field* fields = result->Fetch (); K.SetHexStr (fields[0].GetString ()); - delete result; ///- Sending response ByteBuffer pkt; @@ -885,7 +879,7 @@ bool AuthSocket::_HandleRealmList() ///- Get the user id (else close the connection) // No SQL injection (escaped user name) - QueryResult *result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str()); + QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str()); if (!result) { sLog.outError("[ERROR] user %s tried to login and we cannot find him in the database.",_login.c_str()); @@ -895,7 +889,6 @@ bool AuthSocket::_HandleRealmList() uint32 id = (*result)[0].GetUInt32(); std::string rI = (*result)[1].GetCppString(); - delete result; ///- Update realm list if need m_realmList.UpdateIfNeed(); @@ -935,7 +928,6 @@ bool AuthSocket::_HandleRealmList() { Field *fields = result->Fetch(); AmountOfCharacters = fields[0].GetUInt8(); - delete result; } else AmountOfCharacters = 0; diff --git a/src/trinityrealm/Main.cpp b/src/trinityrealm/Main.cpp index 9b94c61afe2..68e200969e3 100644 --- a/src/trinityrealm/Main.cpp +++ b/src/trinityrealm/Main.cpp @@ -288,7 +288,7 @@ extern int main(int argc, char **argv) { loopCounter = 0; sLog.outDetail("Ping MySQL to keep connection alive"); - delete loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1"); + loginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1"); } #ifdef WIN32 if (m_ServiceStatus == 0) stopEvent = true; diff --git a/src/trinityrealm/RealmList.cpp b/src/trinityrealm/RealmList.cpp index a04a4fd7bfb..5a441de8012 100644 --- a/src/trinityrealm/RealmList.cpp +++ b/src/trinityrealm/RealmList.cpp @@ -83,7 +83,7 @@ void RealmList::UpdateRealms(bool init) { sLog.outDetail("Updating Realm List..."); - QueryResult *result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name"); + QueryResult_AutoPtr result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name"); ///- Circle through results and add them to the realm map if (result) @@ -98,6 +98,5 @@ void RealmList::UpdateRealms(bool init) if (init) sLog.outString("Added realm \"%s\".", fields[1].GetString()); } while(result->NextRow()); - delete result; } } |
