Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve network table error handling #2097

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/api/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/api/stats_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading
Loading