Fix coverity issues (#11809)
* Add check for NULL wc->host * Use sqlite3_exec, if it fails it will be retried on the next health log entries rotation
Stelios Fragkakis committed
Nov 19, 2021 at 16:56 UTC
11b8588c94b37b7a082a041342e69e21a0a81ad5
2 files changed
+29
-13
database/sqlite/sqlite_aclk_alert.c
+13
-3
@@ -751,6 +751,11 @@ void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, stru
751
return;
752
}
753
754
+ if (unlikely(!wc->host)) {
755
+ error_report("ACLK synchronization thread for %s is not linked to HOST", wc->host_guid);
756
+ return;
757
+ }
758
+
759
char *claim_id = is_agent_claimed();
760
if (unlikely(!claim_id))
761
return;
@@ -865,9 +870,14 @@ void sql_aclk_alert_clean_dead_entries(RRDHOST *host)
870
871
buffer_sprintf(sql,"delete from aclk_alert_%s where alert_unique_id not in "
872
" (select unique_id from health_log_%s); ", uuid_str, uuid_str);
868
-
869
- db_execute(buffer_tostring(sql));
870
-
873
+
874
+ char *err_msg = NULL;
875
+ int rc = sqlite3_exec(db_meta, buffer_tostring(sql), NULL, NULL, &err_msg);
876
+ if (rc != SQLITE_OK) {
877
+ error_report("Failed when trying to clean stale ACLK alert entries from aclk_alert_%s, error message \"%s""",
878
+ uuid_str, err_msg);
879
+ sqlite3_free(err_msg);
880
+ }
881
buffer_free(sql);
882
#else
883
UNUSED(host);
database/sqlite/sqlite_aclk_chart.c
+16
-10
@@ -572,18 +572,24 @@ void aclk_receive_chart_reset(struct aclk_database_worker_config *wc, struct acl
572
wc->chart_payload_count = 0;
573
574
RRDHOST *host = wc->host;
575
- rrdhost_rdlock(host);
576
- RRDSET *st;
577
- rrdset_foreach_read(st, host) {
578
- rrdset_rdlock(st);
579
- rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
580
- RRDDIM *rd;
581
- rrddim_foreach_read(rd, st) {
582
- rd->state->aclk_live_status = (rd->state->aclk_live_status == 0);
575
+ if (likely(host)) {
576
+ rrdhost_rdlock(host);
577
+ RRDSET *st;
578
+ rrdset_foreach_read(st, host)
579
+ {
580
+ rrdset_rdlock(st);
581
+ rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
582
+ RRDDIM *rd;
583
+ rrddim_foreach_read(rd, st)
584
+ {
585
+ rd->state->aclk_live_status = (rd->state->aclk_live_status == 0);
586
+ }
587
+ rrdset_unlock(st);
588
}
584
- rrdset_unlock(st);
589
+ rrdhost_unlock(host);
590
}
586
- rrdhost_unlock(host);
591
+ else
592
+ error_report("ACLK synchronization thread for %s is not linked to HOST", wc->host_guid);
593
}
594
else {
595
log_access("AC [%s (%s)]: Restarting chart sync from sequence %"PRIu64, wc->node_id, wc->host ? wc->host->hostname : "N/A", cmd.param1);