Skip to content
Closed
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
10 changes: 9 additions & 1 deletion poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,20 @@ void poll_host(int device_counter, int host_id, int host_thread, int host_thread
MYSQL_RES *result;
MYSQL_ROW row;

//db_connect(LOCAL, &mysql);
local_cnn = db_get_connection(LOCAL);
if (local_cnn == NULL) {
SPINE_LOG(("FATAL: Device[%i] HT[%i] Unable to acquire local DB connection", host_id, host_thread));
return;
}
Comment on lines 234 to +238
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These early returns skip the normal cleanup at the end of poll_host: error_string/buf_size/buf_errors have already been malloc'd above, and mysql_thread_end() is not called. Consider moving these allocations to after the connection is acquired, or routing this path through a shared cleanup block that frees the buffers and sets *host_errors before returning.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Local connection is released before returning on remote failure.

mysql = local_cnn->mysql;

if (set.poller_id > 1 && set.mode == REMOTE_ONLINE) {
remote_cnn = db_get_connection(REMOTE);
if (remote_cnn == NULL) {
SPINE_LOG(("FATAL: Device[%i] HT[%i] Unable to acquire remote DB connection", host_id, host_thread));
db_release_connection(LOCAL, local_cnn->id);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On remote connection acquisition failure, the local connection is released (good), but the function still returns without freeing the already-allocated buffers (error_string/buf_size/buf_errors) and without calling mysql_thread_end(). Please route this return through the same cleanup logic used elsewhere in poll_host (or defer allocations until after both connections are acquired).

Suggested change
db_release_connection(LOCAL, local_cnn->id);
db_release_connection(LOCAL, local_cnn->id);
free(error_string);
free(buf_size);
free(buf_errors);
mysql_thread_end();

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Local connection is released before returning on remote failure.

return;
}
mysqlr = remote_cnn->mysql;
}

Expand Down
Loading