Browse Source

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 3 years ago
parent
commit
11b8588c94
2 changed files with 29 additions and 13 deletions
  1. 13 3
      database/sqlite/sqlite_aclk_alert.c
  2. 16 10
      database/sqlite/sqlite_aclk_chart.c

+ 13 - 3
database/sqlite/sqlite_aclk_alert.c

@@ -751,6 +751,11 @@ void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, stru
         return;
     }
 
+    if (unlikely(!wc->host)) {
+        error_report("ACLK synchronization thread for %s is not linked to HOST", wc->host_guid);
+        return;
+    }
+
     char *claim_id = is_agent_claimed();
     if (unlikely(!claim_id))
         return;
@@ -865,9 +870,14 @@ void sql_aclk_alert_clean_dead_entries(RRDHOST *host)
 
     buffer_sprintf(sql,"delete from aclk_alert_%s where alert_unique_id not in "
                    " (select unique_id from health_log_%s); ", uuid_str, uuid_str);
-
-    db_execute(buffer_tostring(sql));
-
+    
+    char *err_msg = NULL;
+    int rc = sqlite3_exec(db_meta, buffer_tostring(sql), NULL, NULL, &err_msg);
+    if (rc != SQLITE_OK) {
+        error_report("Failed when trying to clean stale ACLK alert entries from aclk_alert_%s, error message \"%s""",
+                     uuid_str, err_msg);
+        sqlite3_free(err_msg);
+    }
     buffer_free(sql);
 #else
     UNUSED(host);

+ 16 - 10
database/sqlite/sqlite_aclk_chart.c

@@ -572,18 +572,24 @@ void aclk_receive_chart_reset(struct aclk_database_worker_config *wc, struct acl
         wc->chart_payload_count = 0;
 
         RRDHOST *host = wc->host;
-        rrdhost_rdlock(host);
-        RRDSET *st;
-        rrdset_foreach_read(st, host) {
-            rrdset_rdlock(st);
-            rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
-            RRDDIM *rd;
-            rrddim_foreach_read(rd, st) {
-                rd->state->aclk_live_status = (rd->state->aclk_live_status == 0);
+        if (likely(host)) {
+            rrdhost_rdlock(host);
+            RRDSET *st;
+            rrdset_foreach_read(st, host)
+            {
+                rrdset_rdlock(st);
+                rrdset_flag_clear(st, RRDSET_FLAG_ACLK);
+                RRDDIM *rd;
+                rrddim_foreach_read(rd, st)
+                {
+                    rd->state->aclk_live_status = (rd->state->aclk_live_status == 0);
+                }
+                rrdset_unlock(st);
             }
-            rrdset_unlock(st);
+            rrdhost_unlock(host);
         }
-        rrdhost_unlock(host);
+        else
+            error_report("ACLK synchronization thread for %s is not linked to HOST", wc->host_guid);
     }
     else {
         log_access("AC [%s (%s)]: Restarting chart sync from sequence %"PRIu64, wc->node_id, wc->host ? wc->host->hostname : "N/A", cmd.param1);