-
Notifications
You must be signed in to change notification settings - Fork 45
fix(poller): add NULL check after db_get_connection #531
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||
| } | ||||||||||||||
| 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); | ||||||||||||||
|
||||||||||||||
| 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.