Index: main/db.c =================================================================== --- main/db.c (revision 405589) +++ main/db.c (working copy) @@ -959,13 +959,12 @@ for (;;) { /* We're ok with spurious wakeups, so we don't worry about a predicate */ ast_cond_wait(&dbcond, &dblock); + if (doexit) { + break; + } if (ast_db_commit_transaction()) { ast_db_rollback_transaction(); } - if (doexit) { - ast_mutex_unlock(&dblock); - break; - } ast_db_begin_transaction(); ast_mutex_unlock(&dblock); sleep(1); @@ -976,10 +975,13 @@ * it once, but that would impose a forced delay of 1 * second always.) */ if (doexit) { - ast_mutex_unlock(&dblock); break; } } + if (ast_db_commit_transaction()) { + ast_db_rollback_transaction(); + } + ast_mutex_unlock(&dblock); return NULL; }