Commit 01eba32f authored by Razvan Becheriu's avatar Razvan Becheriu

[1040] separated delete functions

parent 5f9937b1
...@@ -126,7 +126,7 @@ private: ...@@ -126,7 +126,7 @@ private:
/// @brief Callback that will be called from iface_mgr when data /// @brief Callback that will be called from iface_mgr when data
/// is received over control socket. /// is received over control socket.
/// ///
/// This static callback method is called from IfaceMgr::receive6() method, /// This static callback method is called from IfaceMgr::receive4() method,
/// when there is a new command or configuration sent over control socket /// when there is a new command or configuration sent over control socket
/// (that was sent from some yet unspecified sender). /// (that was sent from some yet unspecified sender).
static void sessionReader(void); static void sessionReader(void);
......
...@@ -2894,7 +2894,7 @@ Dhcpv4Srv::processRelease(Pkt4Ptr& release, AllocEngine::ClientContext4Ptr& cont ...@@ -2894,7 +2894,7 @@ Dhcpv4Srv::processRelease(Pkt4Ptr& release, AllocEngine::ClientContext4Ptr& cont
// Callout didn't indicate to skip the release process. Let's release // Callout didn't indicate to skip the release process. Let's release
// the lease. // the lease.
if (!skip) { if (!skip) {
bool success = LeaseMgrFactory::instance().deleteLease(lease->addr_); bool success = LeaseMgrFactory::instance().deleteLease(lease);
if (success) { if (success) {
......
...@@ -1647,7 +1647,9 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) { ...@@ -1647,7 +1647,9 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
// Renew*Lifetime common code. // Renew*Lifetime common code.
...@@ -1768,7 +1770,9 @@ TEST_F(Dhcpv4SrvTest, RenewDefaultLifetime) { ...@@ -1768,7 +1770,9 @@ TEST_F(Dhcpv4SrvTest, RenewDefaultLifetime) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
// This test verifies that renewal returns the specified valid lifetime // This test verifies that renewal returns the specified valid lifetime
...@@ -1813,7 +1817,9 @@ TEST_F(Dhcpv4SrvTest, RenewHintLifetime) { ...@@ -1813,7 +1817,9 @@ TEST_F(Dhcpv4SrvTest, RenewHintLifetime) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
// This test verifies that renewal returns the min valid lifetime // This test verifies that renewal returns the min valid lifetime
...@@ -1858,7 +1864,9 @@ TEST_F(Dhcpv4SrvTest, RenewMinLifetime) { ...@@ -1858,7 +1864,9 @@ TEST_F(Dhcpv4SrvTest, RenewMinLifetime) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
// This test verifies that renewal returns the max valid lifetime // This test verifies that renewal returns the max valid lifetime
...@@ -1902,7 +1910,9 @@ TEST_F(Dhcpv4SrvTest, RenewMaxLifetime) { ...@@ -1902,7 +1910,9 @@ TEST_F(Dhcpv4SrvTest, RenewMaxLifetime) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(c.addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = c.addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
} // end of Renew*Lifetime } // end of Renew*Lifetime
...@@ -3903,4 +3913,4 @@ TEST_F(Dhcpv4SrvTest, userContext) { ...@@ -3903,4 +3913,4 @@ TEST_F(Dhcpv4SrvTest, userContext) {
/// @todo: Implement proper tests for MySQL lease/host database, /// @todo: Implement proper tests for MySQL lease/host database,
/// see ticket #4214. /// see ticket #4214.
}; // end of anonymous namespace } // namespace
...@@ -1827,7 +1827,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) { ...@@ -1827,7 +1827,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
sort(expected_argument_names.begin(), expected_argument_names.end()); sort(expected_argument_names.begin(), expected_argument_names.end());
EXPECT_TRUE(callback_argument_names_ == expected_argument_names); EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Pkt passed to a callout must be configured to copy retrieved options. // Pkt passed to a callout must be configured to copy retrieved options.
EXPECT_TRUE(callback_qry_options_copy_); EXPECT_TRUE(callback_qry_options_copy_);
...@@ -1896,7 +1898,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) { ...@@ -1896,7 +1898,9 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
EXPECT_EQ(temp_valid, l->valid_lft_); EXPECT_EQ(temp_valid, l->valid_lft_);
EXPECT_EQ(temp_timestamp, l->cltt_); EXPECT_EQ(temp_timestamp, l->cltt_);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Check if the callout handle state was reset after the callout. // Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req); checkCalloutHandleReset(req);
......
...@@ -198,7 +198,7 @@ std::set<std::string> dhcp6_statistics = { ...@@ -198,7 +198,7 @@ std::set<std::string> dhcp6_statistics = {
"pkt6-receive-drop" "pkt6-receive-drop"
}; };
}; // anonymous namespace } // namespace
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
...@@ -1587,6 +1587,7 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer, ...@@ -1587,6 +1587,7 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
if (answer_opt) { if (answer_opt) {
answer->addOption(answer_opt); answer->addOption(answer_opt);
} }
break;
} }
default: default:
break; break;
...@@ -2677,7 +2678,7 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query, ...@@ -2677,7 +2678,7 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
bool success = false; // was the removal operation successful? bool success = false; // was the removal operation successful?
if (!skip) { if (!skip) {
success = LeaseMgrFactory::instance().deleteLease(lease->addr_); success = LeaseMgrFactory::instance().deleteLease(lease);
} }
// Here the success should be true if we removed lease successfully // Here the success should be true if we removed lease successfully
...@@ -2835,7 +2836,7 @@ Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query, ...@@ -2835,7 +2836,7 @@ Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
bool success = false; // was the removal operation successful? bool success = false; // was the removal operation successful?
if (!skip) { if (!skip) {
success = LeaseMgrFactory::instance().deleteLease(lease->addr_); success = LeaseMgrFactory::instance().deleteLease(lease);
} else { } else {
// Callouts decided to skip the next processing step. The next // Callouts decided to skip the next processing step. The next
// processing step would to send the packet, so skip at this // processing step would to send the packet, so skip at this
...@@ -4035,5 +4036,5 @@ Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6 ...@@ -4035,5 +4036,5 @@ Dhcpv6Srv::setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6
} }
} }
}; } // namespace dhcp
}; } // namespace isc
...@@ -1046,7 +1046,9 @@ TEST_F(Dhcpv6SrvTest, RequestBasic) { ...@@ -1046,7 +1046,9 @@ TEST_F(Dhcpv6SrvTest, RequestBasic) {
// check that the lease is really in the database // check that the lease is really in the database
Lease6Ptr l = checkLease(duid_, reply->getOption(D6O_IA_NA), addr); Lease6Ptr l = checkLease(duid_, reply->getOption(D6O_IA_NA), addr);
EXPECT_TRUE(l); EXPECT_TRUE(l);
LeaseMgrFactory::instance().deleteLease(addr->getAddress()); Lease6Ptr lease(new Lease6());
lease->addr_ = addr->getAddress();
LeaseMgrFactory::instance().deleteLease(lease);
} }
// This test verifies that incoming REQUEST can be handled properly, that a // This test verifies that incoming REQUEST can be handled properly, that a
...@@ -1112,7 +1114,9 @@ TEST_F(Dhcpv6SrvTest, pdRequestBasic) { ...@@ -1112,7 +1114,9 @@ TEST_F(Dhcpv6SrvTest, pdRequestBasic) {
// check that the lease is really in the database // check that the lease is really in the database
Lease6Ptr l = checkPdLease(duid_, reply->getOption(D6O_IA_PD), prf); Lease6Ptr l = checkPdLease(duid_, reply->getOption(D6O_IA_PD), prf);
EXPECT_TRUE(l); EXPECT_TRUE(l);
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(prf->getAddress())); Lease6Ptr lease(new Lease6());
lease->addr_ = prf->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
// This test checks that the server is offering different addresses to different // This test checks that the server is offering different addresses to different
...@@ -2975,4 +2979,4 @@ TEST_F(Dhcpv6SrvTest, calculateTeeTimers) { ...@@ -2975,4 +2979,4 @@ TEST_F(Dhcpv6SrvTest, calculateTeeTimers) {
/// @todo: Implement proper tests for MySQL lease/host database, /// @todo: Implement proper tests for MySQL lease/host database,
/// see ticket #4214. /// see ticket #4214.
} // end of anonymous namespace } // namespace
...@@ -433,7 +433,9 @@ Dhcpv6SrvTest::testRenewBasic(Lease::Type type, ...@@ -433,7 +433,9 @@ Dhcpv6SrvTest::testRenewBasic(Lease::Type type,
// equality or difference by 1 between cltt and expected is ok. // equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(renew_addr)); Lease6Ptr lease(new Lease6());
lease->addr_ = renew_addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
void void
...@@ -755,7 +757,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) { ...@@ -755,7 +757,9 @@ Dhcpv6SrvTest::testReleaseReject(Lease::Type type, const IOAddress& addr) {
EXPECT_EQ(1, stat->getInteger().first); EXPECT_EQ(1, stat->getInteger().first);
// Finally, let's cleanup the database // Finally, let's cleanup the database
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr)); lease.reset(new Lease6());
lease->addr_ = addr;
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
} }
void void
...@@ -964,6 +968,6 @@ NakedDhcpv6SrvTest::checkIA_NAStatusCode( ...@@ -964,6 +968,6 @@ NakedDhcpv6SrvTest::checkIA_NAStatusCode(
} }
} }
}; // end of isc::dhcp::test namespace } // namespace test
}; // end of isc::dhcp namespace } // namespace dhcp
}; // end of isc namespace } // namespace isc
...@@ -2857,7 +2857,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Renew) { ...@@ -2857,7 +2857,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Renew) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress())); Lease6Ptr deleted_lease(new Lease6());
deleted_lease->addr_ = addr_opt->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(deleted_lease));
// Check if the callout handle state was reset after the callout. // Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req); checkCalloutHandleReset(req);
...@@ -3976,7 +3978,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Rebind) { ...@@ -3976,7 +3978,9 @@ TEST_F(HooksDhcpv6SrvTest, leaseUpdateLease6Rebind) {
// Equality or difference by 1 between cltt and expected is ok. // Equality or difference by 1 between cltt and expected is ok.
EXPECT_GE(1, abs(cltt - expected)); EXPECT_GE(1, abs(cltt - expected));
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(addr_opt->getAddress())); lease.reset(new Lease6());
lease->addr_ = addr_opt->getAddress();
EXPECT_TRUE(LeaseMgrFactory::instance().deleteLease(lease));
// Check if the callout handle state was reset after the callout. // Check if the callout handle state was reset after the callout.
checkCalloutHandleReset(req); checkCalloutHandleReset(req);
...@@ -4958,4 +4962,4 @@ TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) { ...@@ -4958,4 +4962,4 @@ TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) {
"3io_contextjson_confignetwork_stateserver_config")); "3io_contextjson_confignetwork_stateserver_config"));
} }
} // end of anonymous namespace } // namespace
...@@ -472,7 +472,10 @@ TEST_F(RebindTest, directClientLostLease) { ...@@ -472,7 +472,10 @@ TEST_F(RebindTest, directClientLostLease) {
Lease6 lease_client = client.getLease(0); Lease6 lease_client = client.getLease(0);
// The lease has been acquired. Now, let's explicitly remove it from the // The lease has been acquired. Now, let's explicitly remove it from the
// lease database. // lease database.
LeaseMgrFactory::instance().deleteLease(lease_client.addr_); Lease6Ptr lease(new Lease6());
lease->addr_ = lease_client.addr_;
LeaseMgrFactory::instance().deleteLease(lease);
// Send Rebind. // Send Rebind.
ASSERT_NO_THROW(client.doRebind()); ASSERT_NO_THROW(client.doRebind());
...@@ -604,7 +607,9 @@ TEST_F(RebindTest, relayedClientLostLease) { ...@@ -604,7 +607,9 @@ TEST_F(RebindTest, relayedClientLostLease) {
Lease6 lease_client = client.getLease(0); Lease6 lease_client = client.getLease(0);
// The lease has been acquired. Now, let's explicitly remove it from the // The lease has been acquired. Now, let's explicitly remove it from the
// lease database. // lease database.
LeaseMgrFactory::instance().deleteLease(lease_client.addr_); Lease6Ptr lease(new Lease6());
lease->addr_ = lease_client.addr_;
LeaseMgrFactory::instance().deleteLease(lease);
// Send Rebind. // Send Rebind.
ASSERT_NO_THROW(client.doRebind()); ASSERT_NO_THROW(client.doRebind());
...@@ -1146,5 +1151,4 @@ TEST_F(RebindTest, optionsInheritance) { ...@@ -1146,5 +1151,4 @@ TEST_F(RebindTest, optionsInheritance) {
ASSERT_TRUE(client.hasOptionWithAddress(D6O_SNTP_SERVERS, "3000:2::2")); ASSERT_TRUE(client.hasOptionWithAddress(D6O_SNTP_SERVERS, "3000:2::2"));
} }
} // namespace
} // end of anonymous namespace
...@@ -1074,7 +1074,10 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) { ...@@ -1074,7 +1074,10 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
} }
} }
if (LeaseMgrFactory::instance().deleteLease(addr)) { Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
setSuccessResponse(handle, "IPv4 lease deleted."); setSuccessResponse(handle, "IPv4 lease deleted.");
} else { } else {
setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY); setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
...@@ -1172,7 +1175,10 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) { ...@@ -1172,7 +1175,10 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
// This may throw if the lease couldn't be deleted for // This may throw if the lease couldn't be deleted for
// any reason, but we still want to proceed with other // any reason, but we still want to proceed with other
// leases. // leases.
if (LeaseMgrFactory::instance().deleteLease(lease_addr)) { Lease6Ptr lease(new Lease6());
lease->addr_ = lease_addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
++success_count; ++success_count;
} else { } else {
...@@ -1319,7 +1325,10 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) { ...@@ -1319,7 +1325,10 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) {
} }
} }
if (LeaseMgrFactory::instance().deleteLease(addr)) { Lease6Ptr lease(new Lease6());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
setSuccessResponse(handle, "IPv6 lease deleted."); setSuccessResponse(handle, "IPv6 lease deleted.");
} else { } else {
setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY); setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
......
...@@ -232,6 +232,8 @@ CqlConnection::openDatabase() { ...@@ -232,6 +232,8 @@ CqlConnection::openDatabase() {
try { try {
port_number = boost::lexical_cast<int32_t>(port); port_number = boost::lexical_cast<int32_t>(port);
if (port_number < 1 || port_number > 65535) { if (port_number < 1 || port_number > 65535) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): " "CqlConnection::openDatabase(): "
"port outside of range, expected " "port outside of range, expected "
...@@ -239,6 +241,8 @@ CqlConnection::openDatabase() { ...@@ -239,6 +241,8 @@ CqlConnection::openDatabase() {
<< port); << port);
} }
} catch (const boost::bad_lexical_cast& ex) { } catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid " "CqlConnection::openDatabase(): invalid "
"port, expected castable to int, instead got " "port, expected castable to int, instead got "
...@@ -265,12 +269,16 @@ CqlConnection::openDatabase() { ...@@ -265,12 +269,16 @@ CqlConnection::openDatabase() {
reconnect_wait_time_number = reconnect_wait_time_number =
boost::lexical_cast<int32_t>(reconnect_wait_time); boost::lexical_cast<int32_t>(reconnect_wait_time);
if (reconnect_wait_time_number < 0) { if (reconnect_wait_time_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid reconnect " "CqlConnection::openDatabase(): invalid reconnect "
"wait time, expected positive number, instead got " "wait time, expected positive number, instead got "
<< reconnect_wait_time); << reconnect_wait_time);
} }
} catch (const boost::bad_lexical_cast& ex) { } catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): " "CqlConnection::openDatabase(): "
"invalid reconnect wait time, expected " "invalid reconnect wait time, expected "
...@@ -287,6 +295,8 @@ CqlConnection::openDatabase() { ...@@ -287,6 +295,8 @@ CqlConnection::openDatabase() {
connect_timeout_number = connect_timeout_number =
boost::lexical_cast<int32_t>(connect_timeout); boost::lexical_cast<int32_t>(connect_timeout);
if (connect_timeout_number < 0) { if (connect_timeout_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): " "CqlConnection::openDatabase(): "
"invalid connect timeout, expected " "invalid connect timeout, expected "
...@@ -294,6 +304,8 @@ CqlConnection::openDatabase() { ...@@ -294,6 +304,8 @@ CqlConnection::openDatabase() {
<< connect_timeout); << connect_timeout);
} }
} catch (const boost::bad_lexical_cast& ex) { } catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid connect timeout, " "CqlConnection::openDatabase(): invalid connect timeout, "
"expected castable to int, instead got \"" "expected castable to int, instead got \""
...@@ -308,6 +320,8 @@ CqlConnection::openDatabase() { ...@@ -308,6 +320,8 @@ CqlConnection::openDatabase() {
request_timeout_number = request_timeout_number =
boost::lexical_cast<int32_t>(request_timeout); boost::lexical_cast<int32_t>(request_timeout);
if (request_timeout_number < 0) { if (request_timeout_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): " "CqlConnection::openDatabase(): "
"invalid request timeout, expected " "invalid request timeout, expected "
...@@ -315,6 +329,8 @@ CqlConnection::openDatabase() { ...@@ -315,6 +329,8 @@ CqlConnection::openDatabase() {
<< request_timeout); << request_timeout);
} }
} catch (const boost::bad_lexical_cast& ex) { } catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid request timeout, " "CqlConnection::openDatabase(): invalid request timeout, "
"expected castable to int, instead got \"" "expected castable to int, instead got \""
...@@ -328,6 +344,8 @@ CqlConnection::openDatabase() { ...@@ -328,6 +344,8 @@ CqlConnection::openDatabase() {
try { try {
tcp_keepalive_number = boost::lexical_cast<int32_t>(tcp_keepalive); tcp_keepalive_number = boost::lexical_cast<int32_t>(tcp_keepalive);
if (tcp_keepalive_number < 0) { if (tcp_keepalive_number < 0) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): " "CqlConnection::openDatabase(): "
"invalid TCP keepalive, expected " "invalid TCP keepalive, expected "
...@@ -335,6 +353,8 @@ CqlConnection::openDatabase() { ...@@ -335,6 +353,8 @@ CqlConnection::openDatabase() {
<< tcp_keepalive); << tcp_keepalive);
} }
} catch (const boost::bad_lexical_cast& ex) { } catch (const boost::bad_lexical_cast& ex) {
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOperationError, isc_throw(DbOperationError,
"CqlConnection::openDatabase(): invalid TCP keepalive, " "CqlConnection::openDatabase(): invalid TCP keepalive, "
"expected castable to int, instead got \"" "expected castable to int, instead got \""
...@@ -371,6 +391,10 @@ CqlConnection::openDatabase() { ...@@ -371,6 +391,10 @@ CqlConnection::openDatabase() {
schema_meta_ = cass_session_get_schema_meta(session_); schema_meta_ = cass_session_get_schema_meta(session_);
keyspace_meta_ = cass_schema_meta_keyspace_by_name(schema_meta_, keyspace); keyspace_meta_ = cass_schema_meta_keyspace_by_name(schema_meta_, keyspace);
if (!keyspace_meta_) { if (!keyspace_meta_) {
cass_session_free(session_);
session_ = NULL;
cass_cluster_free(cluster_);
cluster_ = NULL;
isc_throw(DbOpenError, "CqlConnection::openDatabase(): " isc_throw(DbOpenError, "CqlConnection::openDatabase(): "
"!cass_schema_meta_keyspace_by_name()"); "!cass_schema_meta_keyspace_by_name()");
} }
......
...@@ -80,7 +80,7 @@ struct AllocEngineHooks { ...@@ -80,7 +80,7 @@ struct AllocEngineHooks {
// module is called. // module is called.
AllocEngineHooks Hooks; AllocEngineHooks Hooks;
}; // anonymous namespace } // namespace
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
...@@ -1480,7 +1480,7 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx, ...@@ -1480,7 +1480,7 @@ AllocEngine::removeNonmatchingReservedLeases6(ClientContext6& ctx,
// Remove this lease from LeaseMgr as it is reserved to someone // Remove this lease from LeaseMgr as it is reserved to someone
// else or doesn't belong to a pool. // else or doesn't belong to a pool.
LeaseMgrFactory::instance().deleteLease(candidate->addr_); LeaseMgrFactory::instance().deleteLease(candidate);
// Update DNS if needed. // Update DNS if needed.
queueNCR(CHG_REMOVE, candidate); queueNCR(CHG_REMOVE, candidate);
...@@ -1523,7 +1523,7 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx, ...@@ -1523,7 +1523,7 @@ AllocEngine::removeNonmatchingReservedNoHostLeases6(ClientContext6& ctx,
} }
// Remove this lease from LeaseMgr as it doesn't belong to a pool. // Remove this lease from LeaseMgr as it doesn't belong to a pool.
LeaseMgrFactory::instance().deleteLease(candidate->addr_); LeaseMgrFactory::instance().deleteLease(candidate);
// Update DNS if needed. // Update DNS if needed.
queueNCR(CHG_REMOVE, candidate); queueNCR(CHG_REMOVE, candidate);
...@@ -1590,7 +1590,7 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx, ...@@ -1590,7 +1590,7 @@ AllocEngine::removeNonreservedLeases6(ClientContext6& ctx,
// simply remove it from the list. // simply remove it from the list.
// We have reservations, but not for this lease. Release it. // We have reservations, but not for this lease. Release it.
// Remove this lease from LeaseMgr // Remove this lease from LeaseMgr
LeaseMgrFactory::instance().deleteLease((*lease)->addr_); LeaseMgrFactory::instance().deleteLease(*lease);
// Update DNS if required. // Update DNS if required.
queueNCR(CHG_REMOVE, *lease); queueNCR(CHG_REMOVE, *lease);
...@@ -1991,7 +1991,7 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) { ...@@ -1991,7 +1991,7 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
// Oh dear, the lease is no longer valid. We need to get rid of it. // Oh dear, the lease is no longer valid. We need to get rid of it.
// Remove this lease from LeaseMgr // Remove this lease from LeaseMgr
LeaseMgrFactory::instance().deleteLease(lease->addr_); LeaseMgrFactory::instance().deleteLease(lease);