]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2268] Fix a leak upon exception in InMemoryClient's constructor
authorMukund Sivaraman <muks@isc.org>
Sun, 7 Oct 2012 17:55:55 +0000 (23:25 +0530)
committerMukund Sivaraman <muks@isc.org>
Sun, 7 Oct 2012 17:55:55 +0000 (23:25 +0530)
src/lib/datasrc/memory/memory_client.cc
src/lib/datasrc/tests/memory/memory_client_unittest.cc

index c29eca63ca89bd05100a568abe05f968574eabc9..552c5e710e8c9c805e358769793cbcee14c2cd14 100644 (file)
@@ -66,10 +66,15 @@ InMemoryClient::InMemoryClient(util::MemorySegment& mem_sgmt,
                                RRClass rrclass) :
     mem_sgmt_(mem_sgmt),
     rrclass_(rrclass),
-    zone_count_(0),
-    zone_table_(ZoneTable::create(mem_sgmt_, rrclass)),
-    file_name_tree_(FileNameTree::create(mem_sgmt_, false))
-{}
+    zone_count_(0)
+{
+    SegmentObjectHolder<ZoneTable, RRClass> holder(
+        mem_sgmt_, ZoneTable::create(mem_sgmt_, rrclass), rrclass_);
+
+    file_name_tree_ = FileNameTree::create(mem_sgmt_, false);
+
+    zone_table_ = holder.release();
+}
 
 InMemoryClient::~InMemoryClient() {
     FileNameDeleter deleter;
index 2bc9304dd520f583d52756693370b279097fd5d1..4a34badb3127e07bc762d176c994a4a3d5739c3c 100644 (file)
@@ -261,10 +261,13 @@ TEST_F(MemoryClientTest, loadMemoryAllocationFailures) {
     // Just to check that things get cleaned up
 
     for (int i = 1; i < 16; i++) {
+        SCOPED_TRACE("For throw count = " + i);
         mem_sgmt_.setThrowCount(i);
-        EXPECT_THROW(client_->load(Name("example.org"),
-                                   TEST_DATA_DIR "/example.org.zone"),
-                     std::bad_alloc);
+        EXPECT_THROW({
+            InMemoryClient client2(mem_sgmt_, zclass_);
+            client2.load(Name("example.org"),
+                         TEST_DATA_DIR "/example.org.zone");
+        }, std::bad_alloc);
     }
     // Teardown checks for memory segment leaks
 }