From c5e926c01a5a767ed73286b4b5570a4bbb0a26ac Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2016 01:14:47 +0300 Subject: Fix some leaks in unit tests. --- src/gui/widgets/browserbox_unittest.cc | 1 + src/gui/windowmanager_unittest.cc | 1 - src/gui/windows/socialwindow.cpp | 13 +++++++++++++ src/resources/dye/dye_unittest.cc | 2 ++ src/resources/sprite/animatedsprite_unittest.cc | 3 +++ src/utils/xml_unittest.cc | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index e0ff9e13d..b4e54052c 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -148,6 +148,7 @@ TEST_CASE("BrowserBox tests", "browserbox") row = "##1%%2"; box->addRow(row); + delete box; delete client; client = nullptr; } diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc index 6ae3b0e34..3f77888d6 100644 --- a/src/gui/windowmanager_unittest.cc +++ b/src/gui/windowmanager_unittest.cc @@ -672,5 +672,4 @@ TEST_CASE("Windows tests", "windowmanager") delete2(client); delete2(serverFeatures); delete2(inventoryHandler); - windowContainer = nullptr; } diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index 0ab894ba6..d98fec4f1 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -168,6 +168,16 @@ SocialWindow::~SocialWindow() delete2(mAttackFilter); delete2(mPickupFilter); delete2(mFriends); + FOR_EACH (GuildMap::iterator, it, mGuilds) + { + delete (*it).second; + } + mGuilds.clear(); + FOR_EACH (PartyMap::iterator, it, mParties) + { + delete (*it).second; + } + mParties.clear(); } bool SocialWindow::addTab(Guild *const guild) @@ -217,6 +227,9 @@ bool SocialWindow::removeTab(Guild *const guild) bool SocialWindow::addTab(Party *const party) { + if (!party) + return false; + if (mParties.find(party) != mParties.end()) return false; diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc index 6b6f1719a..06abc09c7 100644 --- a/src/resources/dye/dye_unittest.cc +++ b/src/resources/dye/dye_unittest.cc @@ -304,6 +304,8 @@ static void dyeCheck(const std::string &dyeString, { REQUIRE(ptr1[idx] == ptr2[idx]); } + image2->decRef(); + image1->decRef(); } TEST_CASE("Dye real dye") diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc index 8601bed17..b59b4dbbb 100644 --- a/src/resources/sprite/animatedsprite_unittest.cc +++ b/src/resources/sprite/animatedsprite_unittest.cc @@ -89,6 +89,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite") REQUIRE(false == sprite->update(11)); REQUIRE(10 == sprite->getFrameTime()); REQUIRE(0 == sprite->getFrameIndex()); + delete(sprite); } SECTION("basic test 2") @@ -149,6 +150,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite") REQUIRE(true == sprite->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); REQUIRE(4 == sprite->getFrameIndex()); REQUIRE(1 == sprite->getFrameTime()); + delete(sprite); } SECTION("basic test 3") @@ -166,6 +168,7 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite") REQUIRE(true == sprite2->update(1 + 10 + 20 + 10 + 25 + 10 + 10 + 1)); REQUIRE(1 == sprite2->getFrameIndex()); REQUIRE(1 == sprite2->getFrameTime()); + delete(sprite2); } delete client; diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc index d90bfb37d..6168b34e5 100644 --- a/src/utils/xml_unittest.cc +++ b/src/utils/xml_unittest.cc @@ -349,5 +349,6 @@ TEST_CASE("xml doc") // clean again ::remove(tempXmlName); } + delete2(theme); delete2(client); } -- cgit v1.2.3-60-g2f50