]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2850] Handle current_filename_ assignment causing an exception
authorMukund Sivaraman <muks@isc.org>
Wed, 8 May 2013 11:32:16 +0000 (17:02 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 8 May 2013 11:32:21 +0000 (17:02 +0530)
src/lib/datasrc/memory/zone_table_segment_mapped.cc
src/lib/datasrc/memory/zone_table_segment_mapped.h

index 6e0e4156abaa4e61f752fe74f014924433cf2202..3140f9035733e3a0c3375eb7606ab953975f21ae 100644 (file)
@@ -153,7 +153,7 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
     return (true);
 }
 
-void
+MemorySegmentMapped*
 ZoneTableSegmentMapped::openReadWrite(const std::string& filename,
                                       bool create)
 {
@@ -179,10 +179,10 @@ ZoneTableSegmentMapped::openReadWrite(const std::string& filename,
          }
     }
 
-    mem_sgmt_.reset(segment.release());
+    return (segment.release());
 }
 
-void
+MemorySegmentMapped*
 ZoneTableSegmentMapped::openReadOnly(const std::string& filename) {
     // In case the checksum or table header is missing, we throw. We
     // want the segment to be automatically destroyed then.
@@ -229,7 +229,7 @@ ZoneTableSegmentMapped::openReadOnly(const std::string& filename) {
          }
     }
 
-    mem_sgmt_.reset(segment.release());
+    return (segment.release());
 }
 
 void
@@ -263,21 +263,26 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
         sync();
     }
 
+    // In case current_filename_ below fails, we want the segment to be
+    // automatically destroyed.
+    std::auto_ptr<MemorySegmentMapped> segment;
+
     switch (mode) {
     case CREATE:
-        openReadWrite(filename, true);
+        segment.reset(openReadWrite(filename, true));
         break;
 
     case READ_WRITE:
-        openReadWrite(filename, false);
+        segment.reset(openReadWrite(filename, false));
         break;
 
     case READ_ONLY:
-        openReadOnly(filename);
+        segment.reset(openReadOnly(filename));
     }
 
-    current_mode_ = mode;
     current_filename_ = filename;
+    current_mode_ = mode;
+    mem_sgmt_.reset(segment.release());
 }
 
 void
index c212f7cc2f7278e01fac475b89a35bb58da491e4..2d95dd67e0238f26719fa01e5e52b96545e8af0a 100644 (file)
@@ -115,8 +115,9 @@ private:
     bool processHeader(isc::util::MemorySegmentMapped& segment, bool create,
                        std::string& error_msg);
 
-    void openReadWrite(const std::string& filename, bool create);
-    void openReadOnly(const std::string& filename);
+    isc::util::MemorySegmentMapped* openReadWrite(const std::string& filename,
+                                                  bool create);
+    isc::util::MemorySegmentMapped* openReadOnly(const std::string& filename);
 
     template<typename T> T* getHeaderHelper() const;