]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
fixed memory leak and log error messages
authorRazvan Becheriu <razvan@isc.org>
Sun, 7 Apr 2019 09:48:44 +0000 (12:48 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 12 Apr 2019 12:10:41 +0000 (15:10 +0300)
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/pgsql_lease_mgr.cc

index c7c81c4007f3f6e35bf2a9340e3f1502ce3b06e7..1f1b6e4b37ad62852093ea2a58aadb17f29d8b4c 100644 (file)
@@ -60,15 +60,6 @@ MySqlConfigBackendImpl(const DatabaseConnection::ParameterMap& parameters)
 }
 
 MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
-    // Free up the prepared statements, ignoring errors. (What would we do
-    // about them? We're destroying this object and are not really concerned
-    // with errors on a database connection that is about to go away.)
-    for (int i = 0; i < conn_.handle().statements_.size(); ++i) {
-        if (conn_.handle().statements_[i] != NULL) {
-            (void) mysql_stmt_close(conn_.handle().statements_[i]);
-            conn_.handle().statements_[i] = NULL;
-        }
-    }
 }
 
 MySqlBindingPtr
index dc987749d2131db32d0ed343522d5ab201648c33..0c263ec54bf17455b7fcddd6fbc6c4a013738407 100644 (file)
@@ -2455,18 +2455,6 @@ MySqlHostDataSourceImpl(const MySqlConnection::ParameterMap& parameters)
 }
 
 MySqlHostDataSourceImpl::~MySqlHostDataSourceImpl() {
-    // Free up the prepared statements, ignoring errors. (What would we do
-    // about them? We're destroying this object and are not really concerned
-    // with errors on a database connection that is about to go away.)
-    for (int i = 0; i < conn_.handle().statements_.size(); ++i) {
-        if (conn_.handle().statements_[i] != NULL) {
-            (void) mysql_stmt_close(conn_.handle().statements_[i]);
-            conn_.handle().statements_[i] = NULL;
-        }
-    }
-
-    // There is no need to close the database in this destructor: it is
-    // closed in the destructor of the mysql_ member variable.
 }
 
 std::pair<uint32_t, uint32_t>
@@ -2487,14 +2475,14 @@ MySqlHostDataSourceImpl::getVersion() const {
     if (status != 0) {
         mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "unable to prepare MySQL statement <"
-                  << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Execute the prepared statement.
     if (mysql_stmt_execute(stmt) != 0) {
         mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "cannot execute schema version query <"
-                  << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Bind the output of the statement to the appropriate variables.
@@ -2515,14 +2503,14 @@ MySqlHostDataSourceImpl::getVersion() const {
 
     if (mysql_stmt_bind_result(stmt, bind)) {
         isc_throw(DbOperationError, "unable to bind result set for <"
-                  << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Fetch the data.
     if (mysql_stmt_fetch(stmt)) {
         mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "unable to bind result set for <"
-                  << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Discard the statement and its resources
@@ -2531,7 +2519,6 @@ MySqlHostDataSourceImpl::getVersion() const {
     return (std::make_pair(major, minor));
 }
 
-
 void
 MySqlHostDataSourceImpl::addStatement(StatementIndex stindex,
                                       std::vector<MYSQL_BIND>& bind) {
index a11ebf62c649d90132d262b55a091e1716f57a91..bf79c7476b2a1381f45e437bf07ec935e5d583f1 100644 (file)
@@ -2719,21 +2719,23 @@ MySqlLeaseMgr::getVersion() const {
     MYSQL_STMT *stmt = mysql_stmt_init(conn_.handle());
     if (stmt == NULL) {
         isc_throw(DbOperationError, "unable to allocate MySQL prepared "
-                "statement structure, reason: " << mysql_error(conn_.handle()));
+                  "statement structure, reason: " << mysql_error(conn_.handle()));
     }
 
     // Prepare the statement from SQL text.
     const char* version_sql = "SELECT version, minor FROM schema_version";
     int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
     if (status != 0) {
+        mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "unable to prepare MySQL statement <"
                   << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Execute the prepared statement.
     if (mysql_stmt_execute(stmt) != 0) {
+        mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "cannot execute schema version query <"
-                  << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Bind the output of the statement to the appropriate variables.
@@ -2754,14 +2756,14 @@ MySqlLeaseMgr::getVersion() const {
 
     if (mysql_stmt_bind_result(stmt, bind)) {
         isc_throw(DbOperationError, "unable to bind result set for <"
-                << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Fetch the data.
     if (mysql_stmt_fetch(stmt)) {
         mysql_stmt_close(stmt);
         isc_throw(DbOperationError, "unable to bind result set for <"
-                << version_sql << ">, reason: " << mysql_errno(conn_.handle()));
+                  << version_sql << ">, reason: " << mysql_error(conn_.handle()));
     }
 
     // Discard the statement and its resources
index 363a009f1fcfbcbe44cfa56ac35642d747dae1bf..9cf7f7756b2a5574c73640f97895228f1b27afb3 100644 (file)
@@ -2013,9 +2013,11 @@ getHost(const SubnetID& subnet_id,
     return (result);
 }
 
-std::pair<uint32_t, uint32_t> PgSqlHostDataSourceImpl::getVersion() const {
+pair<uint32_t, uint32_t>
+PgSqlHostDataSourceImpl::getVersion() const {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
               DHCPSRV_PGSQL_HOST_DB_GET_VERSION);
+
     const char* version_sql =  "SELECT version, minor FROM schema_version;";
     PgSqlResult r(PQexec(conn_.handle(), version_sql));
     if(PQresultStatus(r) != PGRES_TUPLES_OK) {
@@ -2023,13 +2025,13 @@ std::pair<uint32_t, uint32_t> PgSqlHostDataSourceImpl::getVersion() const {
                   << version_sql << ">, reason: " << PQerrorMessage(conn_.handle()));
     }
 
-    uint32_t version;
-    PgSqlExchange::getColumnValue(r, 0, 0, version);
+    uint32_t major;
+    PgSqlExchange::getColumnValue(r, 0, 0, major);
 
     uint32_t minor;
     PgSqlExchange::getColumnValue(r, 0, 1, minor);
 
-    return (std::make_pair(version, minor));
+    return (make_pair(major, minor));
 }
 
 void
index 45c59627ff04ee0f8d0d6d55f68ad236960a96f3..9fe3f19eeff22a95bc568055b6df0a21859c37e3 100644 (file)
@@ -1888,7 +1888,7 @@ PgSqlLeaseMgr::getVersion() const {
     PgSqlResult r(PQexec(conn_.handle(), version_sql));
     if(PQresultStatus(r) != PGRES_TUPLES_OK) {
         isc_throw(DbOperationError, "unable to execute PostgreSQL statement <"
-                  << version_sql << ", reason: " << PQerrorMessage(conn_.handle()));
+                  << version_sql << ">, reason: " << PQerrorMessage(conn_.handle()));
     }
 
     uint32_t major;