mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Go through network-table.c and ensure error handling is uniform, there were some cases in which an early returning caused by an error could have left prepared SQLite3 statements un-finalized. Whether this is the cause for occassional database locking we are seeing is unclear
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -185,6 +185,9 @@ static int api_network_devices_GET(struct ftl_conn *api)
|
||||
const char *sql_msg = NULL;
|
||||
if(!networkTable_readDevices(db, &device_stmt, &sql_msg))
|
||||
{
|
||||
networkTable_readDevicesFinalize(device_stmt);
|
||||
dbclose(&db);
|
||||
|
||||
// Add SQL message (may be NULL = not available)
|
||||
return send_json_error(api, 500,
|
||||
"database_error",
|
||||
@@ -231,6 +234,11 @@ static int api_network_devices_GET(struct ftl_conn *api)
|
||||
{
|
||||
cJSON_Delete(ips);
|
||||
cJSON_Delete(devices);
|
||||
|
||||
networkTable_readIPsFinalize(ip_stmt);
|
||||
networkTable_readDevicesFinalize(device_stmt);
|
||||
dbclose(&db);
|
||||
|
||||
return send_json_error(api, 500,
|
||||
"database_error",
|
||||
"Could not read network details from database table (getting IP records)",
|
||||
@@ -250,6 +258,9 @@ static int api_network_devices_GET(struct ftl_conn *api)
|
||||
|
||||
if(sql_msg != NULL)
|
||||
{
|
||||
networkTable_readDevicesFinalize(device_stmt);
|
||||
dbclose(&db);
|
||||
|
||||
cJSON_Delete(devices);
|
||||
return send_json_error(api, 500,
|
||||
"database_error",
|
||||
|
||||
@@ -57,7 +57,7 @@ int api_history_database(struct ftl_conn *api)
|
||||
|
||||
|
||||
// Prepare SQLite statement
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
|
||||
if( rc != SQLITE_OK ){
|
||||
log_err("api_stats_database_history() - SQL error prepare (%i): %s",
|
||||
@@ -282,7 +282,7 @@ int api_stats_database_top_items(struct ftl_conn *api)
|
||||
|
||||
|
||||
// Prepare SQLite statement
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
|
||||
if( rc != SQLITE_OK ){
|
||||
log_err("api_stats_database_history() - SQL error prepare (%i): %s",
|
||||
@@ -470,7 +470,7 @@ int api_history_database_clients(struct ftl_conn *api)
|
||||
"ORDER BY client DESC";
|
||||
|
||||
// Prepare SQLite statement
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
|
||||
if( rc != SQLITE_OK ){
|
||||
log_err("api_stats_database_clients() - SQL error prepare outer (%i): %s",
|
||||
@@ -727,7 +727,7 @@ int api_stats_database_upstreams(struct ftl_conn *api)
|
||||
"GROUP BY forward ORDER BY forward";
|
||||
|
||||
// Prepare SQLite statement
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int rc = sqlite3_prepare_v2(db, querystr, -1, &stmt, NULL);
|
||||
if( rc != SQLITE_OK ){
|
||||
log_err("api_stats_database_clients() - SQL error prepare (%i): %s",
|
||||
|
||||
+455
-359
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ bool create_network_table(sqlite3 *db);
|
||||
bool create_network_addresses_table(sqlite3 *db);
|
||||
bool create_network_addresses_with_names_table(sqlite3 *db);
|
||||
void parse_neighbor_cache(sqlite3 *db);
|
||||
void updateMACVendorRecords(sqlite3 *db);
|
||||
bool updateMACVendorRecords(sqlite3 *db);
|
||||
bool unify_hwaddr(sqlite3 *db);
|
||||
char *getMACfromIP(sqlite3 *db, const char* ipaddr) __attribute__((malloc));
|
||||
int getAliasclientIDfromIP(sqlite3 *db, const char *ipaddr);
|
||||
|
||||
Reference in New Issue
Block a user