Skip to content

Commit

Permalink
Merge pull request #185 from pi-hole/fix/database
Browse files Browse the repository at this point in the history
SQLite3: Have to finalize statements before closing database handle
  • Loading branch information
DL6ER committed Jan 6, 2018
1 parent f230696 commit b933f2e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions database.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ void check_database(int rc)

void dbclose(void)
{
sqlite3_close(db);
int rc = sqlite3_close(db);
// Report any error
if( rc )
logg("dbclose() - SQL error (%i): %s", rc, sqlite3_errmsg(db));

// Unlock mutex on the database
pthread_mutex_unlock(&dblock);
}

Expand Down Expand Up @@ -388,8 +393,8 @@ void save_to_DB(void)

// Finish prepared statement
ret = dbquery("END TRANSACTION");
if(!ret){ dbclose(); return; }
sqlite3_finalize(stmt);
int ret2 = sqlite3_finalize(stmt);
if(!ret || ret2 != SQLITE_OK){ dbclose(); return; }

// Store index for next loop interation round and update last time stamp
// in the database only if all queries have been saved successfully
Expand Down

0 comments on commit b933f2e

Please sign in to comment.