Commit 62a0f922 authored by JINMEI Tatuya's avatar JINMEI Tatuya

prevented double close for sqlite3 data sources


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1385 e5f2f494-b856-4b98-b285-d166d9295462
parent f69afcb2
......@@ -25,6 +25,8 @@
#include <boost/shared_ptr.hpp>
#include <exceptions/exceptions.h>
#include <dns/name.h>
#include <dns/rrclass.h>
#include <cc/data.h>
......@@ -47,6 +49,15 @@ class DataSrc;
typedef boost::shared_ptr<DataSrc> DataSrcPtr;
typedef boost::shared_ptr<const DataSrc> ConstDataSrcPtr;
/// This exception represents Backend-independent errors relating to
/// data source operations.
class DataSourceError : public Exception {
public:
DataSourceError(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
};
class AbstractDataSrc {
///
/// \name Constructors, Assignment Operator and Destructor.
......
......@@ -482,7 +482,9 @@ Sqlite3DataSrc::Sqlite3DataSrc() :
}
Sqlite3DataSrc::~Sqlite3DataSrc() {
close();
if (db != NULL) {
close();
}
}
DataSrc::Result
......@@ -688,7 +690,7 @@ Sqlite3DataSrc::findReferral(const Name& qname,
void
Sqlite3DataSrc::open(const string& name) {
if (db != NULL) {
isc_throw(Sqlite3Error, "Duplicate Sqlite3 open with " << name);
isc_throw(DataSourceError, "Duplicate Sqlite3 open with " << name);
}
if (sqlite3_open(name.c_str(), &db) != 0) {
// sqlite3_close() must be called even when open fails.
......@@ -702,7 +704,8 @@ Sqlite3DataSrc::open(const string& name) {
DataSrc::Result
Sqlite3DataSrc::close(void) {
if (db == NULL) {
return (SUCCESS);
isc_throw(DataSourceError,
"Sqlite3 data source is being closed before open");
}
if (q_zone != NULL) {
......
......@@ -367,7 +367,13 @@ TEST_F(Sqlite3DataSourceTest, openFail) {
TEST_F(Sqlite3DataSourceTest, doubleOpen) {
// An attempt of duplicate open should trigger an exception.
EXPECT_THROW(data_source.init(SQLITE_DBFILE_EXAMPLE), Sqlite3Error);
EXPECT_THROW(data_source.init(SQLITE_DBFILE_EXAMPLE), DataSourceError);
}
TEST_F(Sqlite3DataSourceTest, doubleClose) {
// An attempt of duplicate close should trigger an exception.
EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
EXPECT_THROW(data_source.close(), DataSourceError);
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
......
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