]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2206] Add a ZoneTableSegment::destroy() method
authorMukund Sivaraman <muks@isc.org>
Wed, 3 Oct 2012 04:40:32 +0000 (10:10 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 3 Oct 2012 04:40:45 +0000 (10:10 +0530)
Also update doc comments asking callers to use the destroy() method.

src/lib/datasrc/memory/zone_table_segment.cc
src/lib/datasrc/memory/zone_table_segment.h
src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc

index 94357c8a7c9d1066b0b2b35f25cbaf2a47ec4716..7a80e3c4c1c3b59ca5b9af8b4c4884eb48bf239d 100644 (file)
@@ -28,6 +28,11 @@ ZoneTableSegment::create(const isc::data::Element&) {
     return (new ZoneTableSegmentLocal);
 }
 
+void
+ZoneTableSegment::destroy(ZoneTableSegment *segment) {
+    delete segment;
+}
+
 } // namespace memory
 } // namespace datasrc
 } // namespace isc
index 99cb0518493aede3ff6123f2e70fdfcf7bdd3643..85050196f5c8206208bb0c26848aea1b31433750 100644 (file)
@@ -74,17 +74,29 @@ public:
     /// \return Returns the ZoneTableHeader for this zone table segment.
     virtual isc::util::MemorySegment& getMemorySegment() = 0;
 
-    /// \brief Create a subclass depending on the memory segment model
+    /// \brief Create an instance depending on the memory segment model
     ///
     /// This is a factory method to create a derived ZoneTableSegment
-    /// object based on the \c config passed.
+    /// object based on the \c config passed. The method returns a
+    /// dynamically-allocated object. The caller is responsible for
+    /// destroying it with \c ZoneTableSegment::destroy().
     ///
-    /// FIXME: For now, we always return ZoneTableSegmentLocal.
+    /// FIXME: For now, we always return ZoneTableSegmentLocal
+    /// regardless of the passed \c config.
     ///
     /// \param config The configuration based on which a derived object
     ///               is returned.
     /// \return Returns a ZoneTableSegment object
     static ZoneTableSegment* create(const isc::data::Element& config);
+
+    /// \brief Destroy a ZoneTableSegment
+    ///
+    /// This method destroys the passed ZoneTableSegment. It must be
+    /// passed a segment previously created by \c
+    /// ZoneTableSegment::create().
+    ///
+    /// \param segment The segment to destroy.
+    static void destroy(ZoneTableSegment* segment);
 };
 
 } // namespace memory
index 3cc65b72705857e0c14b8896ae39e61448af7bb1..f8c58fe9e1d1375a65750620ea19f021b5d2e6d0 100644 (file)
@@ -24,17 +24,17 @@ namespace {
 
 TEST(ZoneTableSegment, create) {
     const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
+    ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
 
     // By default, a local zone table segment is created.
-    EXPECT_NE(static_cast<void*>(NULL), seg.get());
+    EXPECT_NE(static_cast<void*>(NULL), seg);
+
+    ZoneTableSegment::destroy(seg);
 }
 
 TEST(ZoneTableSegment, getHeader) {
     const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
+    ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
 
     // getHeader() should never return NULL.
     ZoneTableHeader* header = seg->getHeader();
@@ -43,16 +43,19 @@ TEST(ZoneTableSegment, getHeader) {
     // The zone table is unset.
     ZoneTable* table = header->getTable();
     EXPECT_EQ(static_cast<void*>(NULL), table);
+
+    ZoneTableSegment::destroy(seg);
 }
 
 TEST(ZoneTableSegment, getMemorySegment) {
     // This doesn't do anything fun except test the API.
     const ElementPtr config = Element::fromJSON("{}");
-    auto_ptr<ZoneTableSegment>
-        seg(ZoneTableSegment::create((*config.get())));
+    ZoneTableSegment* seg = ZoneTableSegment::create((*config.get()));
 
     MemorySegment& mem_sgmt = seg->getMemorySegment();
     EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
+
+    ZoneTableSegment::destroy(seg);
 }
 
 } // anonymous namespace