From 144c91ab9689c8db18797f069ea5b35eb3584d49 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Thu, 21 Apr 2011 10:31:31 +0200 Subject: [PATCH] Free database results on class destruction (e.g. when reference count == 0) --- bacula/src/cats/dbi.c | 2 +- bacula/src/cats/ingres.c | 2 +- bacula/src/cats/mysql.c | 2 +- bacula/src/cats/postgresql.c | 2 +- bacula/src/cats/sqlite.c | 8 +++----- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index c2872a6dca..3181e8b49b 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -336,9 +336,9 @@ void B_DB_DBI::db_close_database(JCR *jcr) { db_end_transaction(jcr); P(mutex); - sql_free_result(); m_ref_count--; if (m_ref_count == 0) { + sql_free_result(); db_list->remove(this); if (m_connected && m_db_handle) { dbi_shutdown_r(m_instance); diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index 0cc52a16f8..feb1aecf49 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -283,9 +283,9 @@ void B_DB_INGRES::db_close_database(JCR *jcr) { db_end_transaction(jcr); P(mutex); - sql_free_result(); m_ref_count--; if (m_ref_count == 0) { + sql_free_result(); db_list->remove(this); if (m_connected && m_db_handle) { INGdisconnectDB(m_db_handle); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 4c5bbfbd97..ad81f1b56b 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -236,10 +236,10 @@ void B_DB_MYSQL::db_close_database(JCR *jcr) { db_end_transaction(jcr); P(mutex); - sql_free_result(); m_ref_count--; Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", m_ref_count, m_connected, m_db_handle); if (m_ref_count == 0) { + sql_free_result(); db_list->remove(this); if (m_connected) { Dmsg1(100, "close db=%p\n", m_db_handle); diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 924b7548f9..1f35b1634f 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -273,9 +273,9 @@ void B_DB_POSTGRESQL::db_close_database(JCR *jcr) { db_end_transaction(jcr); P(mutex); - sql_free_result(); m_ref_count--; if (m_ref_count == 0) { + sql_free_result(); db_list->remove(this); if (m_connected && m_db_handle) { PQfinish(m_db_handle); diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 5a7f016d0e..2ca68f0689 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -413,7 +413,7 @@ struct rh_data { /* * Convert SQLite's callback into Bacula DB callback */ -static int sqlite_sqlite_result(void *arh_data, int num_fields, char **rows, char **col_names) +static int sqlite_result_handler(void *arh_data, int num_fields, char **rows, char **col_names) { struct rh_data *rh_data = (struct rh_data *)arh_data; @@ -455,7 +455,7 @@ bool B_DB_SQLITE::db_sql_query(const char *query, DB_RESULT_HANDLER *result_hand rh_data.initialized = false; rh_data.result_handler = result_handler; - stat = sqlite3_exec(m_db_handle, query, sqlite_sqlite_result, + stat = sqlite3_exec(m_db_handle, query, sqlite_result_handler, (void *)&rh_data, &m_sqlite_errmsg); if (stat != SQLITE_OK) { @@ -482,9 +482,7 @@ bool B_DB_SQLITE::sql_query(const char *query, int flags) Dmsg1(500, "sql_query starts with '%s'\n", query); - if (m_result) { - sql_free_result(); - } + sql_free_result(); if (m_sqlite_errmsg) { sqlite3_free(m_sqlite_errmsg); m_sqlite_errmsg = NULL; -- 2.39.5