From: Marco van Wieringen Date: Fri, 15 Jun 2012 12:16:58 +0000 (+0200) Subject: Fix bug #1893 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8072c709e84dd15a87dae9b76159ef6fc9ac2884;p=bacula%2Fbacula Fix bug #1893 Only try to close an database transaction when the database is opened. Only destroy an rwl_lock when it is initialized. As dbcheck only calls db_init_database and then db_close_database the database is never opened and we try to end an transaction on a non-opened database, the rwl_destroy will also give an error (which is ignored) as the rwl_lock is only initialized on opening of the database. --- diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index 1bf948fecc..0dcf2cb026 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -341,7 +341,9 @@ bail_out: void B_DB_DBI::db_close_database(JCR *jcr) { - db_end_transaction(jcr); + if (m_connected) { + db_end_transaction(jcr); + } P(mutex); m_ref_count--; if (m_ref_count == 0) { @@ -352,7 +354,9 @@ void B_DB_DBI::db_close_database(JCR *jcr) m_db_handle = NULL; m_instance = NULL; } - rwl_destroy(&m_lock); + if (rwl_is_init(&m_lock)) { + rwl_destroy(&m_lock); + } free_pool_memory(errmsg); free_pool_memory(cmd); free_pool_memory(cached_path); diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index b48fcf9052..9199594079 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -288,7 +288,9 @@ bail_out: void B_DB_INGRES::db_close_database(JCR *jcr) { - db_end_transaction(jcr); + if (m_connected) { + db_end_transaction(jcr); + } P(mutex); m_ref_count--; if (m_ref_count == 0) { @@ -300,7 +302,9 @@ void B_DB_INGRES::db_close_database(JCR *jcr) if (m_query_filters) { db_destroy_query_filters(m_query_filters); } - rwl_destroy(&m_lock); + if (rwl_is_init(&m_lock)) { + rwl_destroy(&m_lock); + } free_pool_memory(errmsg); free_pool_memory(cmd); free_pool_memory(cached_path); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 26e723e47a..f1be9260e1 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -241,7 +241,9 @@ bail_out: void B_DB_MYSQL::db_close_database(JCR *jcr) { - db_end_transaction(jcr); + if (m_connected) { + db_end_transaction(jcr); + } P(mutex); m_ref_count--; Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", m_ref_count, m_connected, m_db_handle); @@ -256,7 +258,9 @@ void B_DB_MYSQL::db_close_database(JCR *jcr) // mysql_server_end(); #endif } - rwl_destroy(&m_lock); + if (rwl_is_init(&m_lock)) { + rwl_destroy(&m_lock); + } free_pool_memory(errmsg); free_pool_memory(cmd); free_pool_memory(cached_path); diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 618b45b0ab..d3ce6e3672 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -278,7 +278,9 @@ bail_out: void B_DB_POSTGRESQL::db_close_database(JCR *jcr) { - db_end_transaction(jcr); + if (m_connected) { + db_end_transaction(jcr); + } P(mutex); m_ref_count--; if (m_ref_count == 0) { @@ -287,7 +289,9 @@ void B_DB_POSTGRESQL::db_close_database(JCR *jcr) if (m_connected && m_db_handle) { PQfinish(m_db_handle); } - rwl_destroy(&m_lock); + if (rwl_is_init(&m_lock)) { + rwl_destroy(&m_lock); + } free_pool_memory(errmsg); free_pool_memory(cmd); free_pool_memory(cached_path); diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index e012a7fd8e..5957513da7 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -230,7 +230,9 @@ bail_out: void B_DB_SQLITE::db_close_database(JCR *jcr) { - db_end_transaction(jcr); + if (m_connected) { + db_end_transaction(jcr); + } P(mutex); m_ref_count--; if (m_ref_count == 0) { @@ -239,7 +241,9 @@ void B_DB_SQLITE::db_close_database(JCR *jcr) if (m_connected && m_db_handle) { sqlite3_close(m_db_handle); } - rwl_destroy(&m_lock); + if (rwl_is_init(&m_lock)) { + rwl_destroy(&m_lock); + } free_pool_memory(errmsg); free_pool_memory(cmd); free_pool_memory(cached_path); diff --git a/bacula/src/lib/rwlock.c b/bacula/src/lib/rwlock.c index ad4f38b93d..bc001ac13c 100644 --- a/bacula/src/lib/rwlock.c +++ b/bacula/src/lib/rwlock.c @@ -113,6 +113,11 @@ int rwl_destroy(brwlock_t *rwl) return (stat != 0 ? stat : (stat1 != 0 ? stat1 : stat2)); } +bool rwl_is_init(brwlock_t *rwl) +{ + return (rwl->valid == RWLOCK_VALID); +} + /* * Handle cleanup when the read lock condition variable * wait is released. diff --git a/bacula/src/lib/rwlock.h b/bacula/src/lib/rwlock.h index c07e5c6875..334938bcf5 100644 --- a/bacula/src/lib/rwlock.h +++ b/bacula/src/lib/rwlock.h @@ -73,6 +73,7 @@ typedef struct s_rwsteal_tag { */ extern int rwl_init(brwlock_t *wrlock, int priority=0); extern int rwl_destroy(brwlock_t *rwlock); +extern bool rwl_is_init(brwlock_t *rwl); extern int rwl_readlock(brwlock_t *rwlock); extern int rwl_readtrylock(brwlock_t *rwlock); extern int rwl_readunlock(brwlock_t *rwlock);