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) {
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);
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) {
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);
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);
// 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);
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) {
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);
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) {
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);
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.
*/
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);