Commit 18094701 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[github21] Segfault condition fixed

 If the keyspace is not present, session_ will be null and
 it would segfault in CQLConnection destructor.
parent ab934d8b
...@@ -30,23 +30,33 @@ CqlConnection::CqlConnection(const ParameterMap& parameters) : ...@@ -30,23 +30,33 @@ CqlConnection::CqlConnection(const ParameterMap& parameters) :
CqlConnection::~CqlConnection() { CqlConnection::~CqlConnection() {
// Free up the prepared statements, ignoring errors. // Free up the prepared statements, ignoring errors.
// Session and connection resources are deallocated. // Session and connection resources are deallocated.
CassError rc; CassError rc = CASS_OK;
std::string error;
for (int i = 0; i < statements_.size(); i++) { for (int i = 0; i < statements_.size(); i++) {
if (statements_[i]) { if (statements_[i]) {
cass_prepared_free(statements_[i]); cass_prepared_free(statements_[i]);
} }
statements_[i] = NULL; statements_[i] = NULL;
} }
CassFuture* close_future = cass_session_close(session_);
cass_future_wait(close_future); if (session_) {
std::string error; CassFuture* close_future = cass_session_close(session_);
checkStatementError(error, close_future, "could not close connection to DB"); cass_future_wait(close_future);
rc = cass_future_error_code(close_future); checkStatementError(error, close_future, "could not close connection to DB");
cass_future_free(close_future); rc = cass_future_error_code(close_future);
cass_session_free(session_); cass_future_free(close_future);
session_ = NULL; cass_session_free(session_);
cass_cluster_free(cluster_); session_ = NULL;
cluster_ = NULL; }
if (cluster_) {
cass_cluster_free(cluster_);
cluster_ = NULL;
}
// We're closing the connection anyway. Let's not throw at this
// stage
if (rc != CASS_OK) { if (rc != CASS_OK) {
isc_throw(DbOpenError, error); isc_throw(DbOpenError, error);
} }
......
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