Commit 4cac3ddb authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2850] Destroy ZoneTableSegment object upon exception (see full log)

Ideally, this should use something like a SegmentObjectHolder, but a
SegmentObjectHolder takes unnecessary arguments. In this limited
usecase, ZoneTableSegment::destroy() just calls its destructor, so
std::auto_ptr should be ok here.
parent eda6761d
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/interprocess/file_mapping.hpp> #include <boost/interprocess/file_mapping.hpp>
#include <memory>
#include <cerrno> #include <cerrno>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -51,17 +52,17 @@ protected: ...@@ -51,17 +52,17 @@ protected:
Element::fromJSON( Element::fromJSON(
"{\"mapped-file\": \"" + std::string(mapped_file2) + "\"}")) "{\"mapped-file\": \"" + std::string(mapped_file2) + "\"}"))
{ {
EXPECT_NE(static_cast<void*>(NULL), ztable_segment_); EXPECT_NE(static_cast<void*>(NULL), ztable_segment_.get());
// Verify that a ZoneTableSegmentMapped is created. // Verify that a ZoneTableSegmentMapped is created.
ZoneTableSegmentMapped* mapped_segment = ZoneTableSegmentMapped* mapped_segment =
dynamic_cast<ZoneTableSegmentMapped*>(ztable_segment_); dynamic_cast<ZoneTableSegmentMapped*>(ztable_segment_.get());
EXPECT_NE(static_cast<void*>(NULL), mapped_segment); EXPECT_NE(static_cast<void*>(NULL), mapped_segment);
createTestData(); createTestData();
} }
~ZoneTableSegmentMappedTest() { ~ZoneTableSegmentMappedTest() {
ZoneTableSegment::destroy(ztable_segment_); ZoneTableSegment::destroy(ztable_segment_.release());
boost::interprocess::file_mapping::remove(mapped_file); boost::interprocess::file_mapping::remove(mapped_file);
boost::interprocess::file_mapping::remove(mapped_file2); boost::interprocess::file_mapping::remove(mapped_file2);
} }
...@@ -81,7 +82,9 @@ protected: ...@@ -81,7 +82,9 @@ protected:
void addData(MemorySegment& segment); void addData(MemorySegment& segment);
bool verifyData(const MemorySegment& segment); bool verifyData(const MemorySegment& segment);
ZoneTableSegment* ztable_segment_; // Ideally, this should be something similar to a
// SegmentObjectHolder, not an auto_ptr.
std::auto_ptr<ZoneTableSegment> ztable_segment_;
const ConstElementPtr config_params_; const ConstElementPtr config_params_;
const ConstElementPtr config_params2_; const ConstElementPtr config_params2_;
std::vector<TestDataElement> test_data_; std::vector<TestDataElement> test_data_;
......
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