From a5e45cef061b921981012176ad7dc9cb5e03dacc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 5 Jul 2011 22:33:12 +0300 Subject: Fix memory leak in shop window, add missing initialisation to BeingCacheEntry. Small code style fix. --- src/being.cpp | 4 +++- src/gui/shopwindow.cpp | 4 ++-- src/gui/widgets/shopitems.cpp | 10 ++++++++++ src/gui/widgets/shopitems.h | 7 +++++++ src/resources/resourcemanager.cpp | 3 ++- 5 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index acfe9e445..4e4b64061 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -99,7 +99,9 @@ class BeingCacheEntry mPartyName(""), mLevel(0), mPvpRank(0), - mTime(0) + mTime(0), + mIp(""), + mIsAdvanced(false) { } diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index fdfea5d15..c6c41884d 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -190,12 +190,12 @@ void ShopWindow::action(const gcn::ActionEvent &event) else if (event.getId() == "delete buy" && mBuyShopItemList && mBuyShopItemList->getSelected() >= 0) { - mBuyShopItems->erase(mBuyShopItemList->getSelected()); + mBuyShopItems->del(mBuyShopItemList->getSelected()); } else if (event.getId() == "delete sell" && mSellShopItemList && mSellShopItemList->getSelected() >= 0) { - mSellShopItems->erase(mSellShopItemList->getSelected()); + mSellShopItems->del(mSellShopItemList->getSelected()); } else if (event.getId() == "announce buy" && mBuyShopItems && mBuyShopItems->getNumberOfElements() > 0) diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index 85ee0a181..c5bcd88c4 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -101,6 +101,16 @@ void ShopItems::erase(unsigned int i) mShopItems.erase(mShopItems.begin() + i); } +void ShopItems::del(unsigned int i) +{ + if (i >= mShopItems.size()) + return; + + ShopItem *item = *(mShopItems.begin() + i); + mShopItems.erase(mShopItems.begin() + i); + delete item; +} + void ShopItems::clear() { delete_all(mShopItems); diff --git a/src/gui/widgets/shopitems.h b/src/gui/widgets/shopitems.h index cc444fe85..abfcffb71 100644 --- a/src/gui/widgets/shopitems.h +++ b/src/gui/widgets/shopitems.h @@ -95,6 +95,13 @@ class ShopItems : public gcn::ListModel */ void erase(unsigned int i); + /** + * Removes an element from the shop and destroy it. + * + * @param i index to remove + */ + void del(unsigned int i); + /** * Clears the list of items in the shop. */ diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 78ca6a284..ad188ec1c 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -752,7 +752,8 @@ Image *ResourceManager::getRescaled(Image *image, int width, int height) if (!image) return 0; - std::string idPath = image->getIdPath() + strprintf("_rescaled%dx%d", width, height); + std::string idPath = image->getIdPath() + strprintf( + "_rescaled%dx%d", width, height); RescaledLoader l = { this, image, width, height }; Image *img = static_cast(get(idPath, RescaledLoader::load, &l)); return img; -- cgit v1.2.3-70-g09d2