Commit e6d1be1a authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2850] Handle current_filename_ assignment causing an exception

parent 148c5bbf
...@@ -153,7 +153,7 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment, ...@@ -153,7 +153,7 @@ ZoneTableSegmentMapped::processHeader(MemorySegmentMapped& segment,
return (true); return (true);
} }
void MemorySegmentMapped*
ZoneTableSegmentMapped::openReadWrite(const std::string& filename, ZoneTableSegmentMapped::openReadWrite(const std::string& filename,
bool create) bool create)
{ {
...@@ -179,10 +179,10 @@ ZoneTableSegmentMapped::openReadWrite(const std::string& filename, ...@@ -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) { ZoneTableSegmentMapped::openReadOnly(const std::string& filename) {
// In case the checksum or table header is missing, we throw. We // In case the checksum or table header is missing, we throw. We
// want the segment to be automatically destroyed then. // want the segment to be automatically destroyed then.
...@@ -229,7 +229,7 @@ ZoneTableSegmentMapped::openReadOnly(const std::string& filename) { ...@@ -229,7 +229,7 @@ ZoneTableSegmentMapped::openReadOnly(const std::string& filename) {
} }
} }
mem_sgmt_.reset(segment.release()); return (segment.release());
} }
void void
...@@ -263,21 +263,26 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode, ...@@ -263,21 +263,26 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
sync(); sync();
} }
// In case current_filename_ below fails, we want the segment to be
// automatically destroyed.
std::auto_ptr<MemorySegmentMapped> segment;
switch (mode) { switch (mode) {
case CREATE: case CREATE:
openReadWrite(filename, true); segment.reset(openReadWrite(filename, true));
break; break;
case READ_WRITE: case READ_WRITE:
openReadWrite(filename, false); segment.reset(openReadWrite(filename, false));
break; break;
case READ_ONLY: case READ_ONLY:
openReadOnly(filename); segment.reset(openReadOnly(filename));
} }
current_mode_ = mode;
current_filename_ = filename; current_filename_ = filename;
current_mode_ = mode;
mem_sgmt_.reset(segment.release());
} }
void void
......
...@@ -115,8 +115,9 @@ private: ...@@ -115,8 +115,9 @@ private:
bool processHeader(isc::util::MemorySegmentMapped& segment, bool create, bool processHeader(isc::util::MemorySegmentMapped& segment, bool create,
std::string& error_msg); std::string& error_msg);
void openReadWrite(const std::string& filename, bool create); isc::util::MemorySegmentMapped* openReadWrite(const std::string& filename,
void openReadOnly(const std::string& filename); bool create);
isc::util::MemorySegmentMapped* openReadOnly(const std::string& filename);
template<typename T> T* getHeaderHelper() const; template<typename T> T* getHeaderHelper() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment