Browse Source

[2836] Store the address for whole lifetime

Store the named address for the whole lifetime of the zone data updater.
This should be better for performance.
Michal 'vorner' Vaner 12 years ago
parent
commit
29f6d05f66

+ 0 - 10
src/lib/datasrc/memory/zone_data_updater.cc

@@ -417,7 +417,6 @@ ZoneDataUpdater::add(const ConstRRsetPtr& rrset,
 
     // Store the address, it may change during growth and the address inside
     // would get updated.
-    mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_);
     bool added = false;
     do {
         try {
@@ -429,18 +428,9 @@ ZoneDataUpdater::add(const ConstRRsetPtr& rrset,
             zone_data_ =
                 static_cast<ZoneData*>(
                     mem_sgmt_.getNamedAddress("updater_zone_data"));
-        } catch (...) {
-            // In case of other exceptions, they are propagated. But clean up
-            // the temporary address stored there (this is shorter than
-            // RAII class in this case).
-            mem_sgmt_.clearNamedAddress("updater_zone_data");
-            throw;
         }
         // Retry if it didn't add due to the growth
     } while (!added);
-
-    // Clean up the named address
-    mem_sgmt_.clearNamedAddress("updater_zone_data");
 }
 
 } // namespace memory

+ 4 - 1
src/lib/datasrc/memory/zone_data_updater.h

@@ -74,10 +74,13 @@ public:
        zone_name_(zone_name),
        hash_(NULL),
        zone_data_(&zone_data)
-    {}
+    {
+        mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_);
+    }
 
     /// The destructor.
     ~ZoneDataUpdater() {
+        mem_sgmt_.clearNamedAddress("updater_zone_data");
         delete hash_;
     }
 

+ 2 - 0
src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc

@@ -92,6 +92,8 @@ protected:
     ~ZoneDataUpdaterTest() {
         if (updater_) {
             ZoneData::destroy(*mem_sgmt_, updater_->getZoneData(), zclass_);
+            // Release the updater, so it frees all memory inside the segment too
+            updater_.reset();
         }
         if (!mem_sgmt_->allMemoryDeallocated()) {
             ADD_FAILURE() << "Memory leak detected";