diff options
author | Huynh Tran <nthuynh75@gmail.com> | 2005-06-30 20:46:57 +0000 |
---|---|---|
committer | Huynh Tran <nthuynh75@gmail.com> | 2005-06-30 20:46:57 +0000 |
commit | 38cfcdd2b7681fc32b1464a4905c721246cf6d75 (patch) | |
tree | a4c6aca110f71fe221e66cdf57d4c5b66a8501a4 /src/account.cpp | |
parent | a5aee1322f498537f8de83123099bbfcb2e3a969 (diff) | |
download | manaserv-38cfcdd2b7681fc32b1464a4905c721246cf6d75.tar.gz manaserv-38cfcdd2b7681fc32b1464a4905c721246cf6d75.tar.bz2 manaserv-38cfcdd2b7681fc32b1464a4905c721246cf6d75.tar.xz manaserv-38cfcdd2b7681fc32b1464a4905c721246cf6d75.zip |
Fixed memory leak, implemented delAccount() + unit tests and now using reference-counted smart pointers to facilitate the memory management.
Diffstat (limited to 'src/account.cpp')
-rw-r--r-- | src/account.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/account.cpp b/src/account.cpp index 97b723a0..c44af2d9 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -70,15 +70,8 @@ Account::Account(const std::string& name, Account::~Account(void) throw() { - for (Beings::iterator it = mCharacters.begin(); - it != mCharacters.end(); - ++it) - { - if (*it != 0) { - delete (*it); - *it = 0; - } - } + // mCharacters is a list of smart pointers which will take care about + // deallocating the memory so nothing to deallocate here :) } @@ -177,9 +170,9 @@ Account::setCharacters(const Beings& characters) * Add a new character. */ void -Account::addCharacter(Being* character) +Account::addCharacter(BeingPtr character) { - if (character) { + if (character.get() != 0) { mCharacters.push_back(character); } } @@ -204,11 +197,11 @@ Account::getCharacter(const std::string& name) Beings::iterator it = std::find_if(mCharacters.begin(), mCharacters.end(), - std::bind2nd(obj_name_is<Being*>(), name) + std::bind2nd(obj_name_is<BeingPtr>(), name) ); if (it != mCharacters.end()) { - return (*it); + return (*it).get(); } return 0; |