]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix bug #1893
authorMarco van Wieringen <mvw@planets.elm.net>
Fri, 15 Jun 2012 12:16:58 +0000 (14:16 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:50:49 +0000 (14:50 +0200)
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.

bacula/src/cats/dbi.c
bacula/src/cats/ingres.c
bacula/src/cats/mysql.c
bacula/src/cats/postgresql.c
bacula/src/cats/sqlite.c
bacula/src/lib/rwlock.c
bacula/src/lib/rwlock.h

index 1bf948fecc2dfcc56670001464dbf36f55ea3cf6..0dcf2cb0261c88f8c69b8a7a32853e3429d46ce2 100644 (file)
@@ -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);
index b48fcf9052024eb17f5b71b648b78e51998b29f9..9199594079e37083e019ed4c6993081836951b76 100755 (executable)
@@ -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);
index 26e723e47ab19a385f5677f89867508da8449a50..f1be9260e13da61f8996696d78eadc234eda0623 100644 (file)
@@ -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);
index 618b45b0abb938a8ee5b010ef6299b51a20e7ca8..d3ce6e3672ef7b330c3b01a3abd33c590c113ea6 100644 (file)
@@ -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);
index e012a7fd8e62673ad3f5899612ec3a029d4e0e27..5957513da7f67934ed1be00e30fbc884d1336193 100644 (file)
@@ -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);
index ad4f38b93d09387e3a3f9ae8b63d7620f0d97663..bc001ac13c5db0aa0b100178ba08ec3d4c51a2b6 100644 (file)
@@ -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.
index c07e5c68755b357c1de3f267d38e1b82f41d5b5c..334938bcf58d032609d73e398bb2f03848f2689d 100644 (file)
@@ -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);