Fix coverity issues (#14543)
* Fix coverity 383236: Resource leak * Fix coverity 382915 : Logically dead code * Fix coverity 379133 : Division or modulo by float zero * Fix coverity 382783 : Copy into fixed size buffer * Fix coverity 381151 : Missing unlock * Fix coverity 381903 : Dereference after null check
Stelios Fragkakis committed
Feb 21, 2023 at 09:53 UTC
bde40023ed79c9f6ee42dbd85ab92b2ba2e1fa70
6 files changed
+10
-8
aclk/aclk_rx_msgs.c
+4
-6
@@ -272,13 +272,12 @@ int create_node_instance_result(const char *msg, size_t msg_len)
272
.live = 0,
273
.queryable = 1,
274
.session_id = aclk_session_newarch,
275
- .node_id = res.node_id
275
+ .node_id = res.node_id,
276
+ .capabilities = NULL
277
};
278
279
RRDHOST *host = rrdhost_find_by_guid(res.machine_guid);
279
- if (host) {
280
- // not all host must have RRDHOST struct created for them
281
- // if they never connected during runtime of agent
280
+ if (likely(host)) {
281
if (host == localhost) {
282
node_state_update.live = 1;
283
node_state_update.hops = 0;
@@ -286,10 +285,9 @@ int create_node_instance_result(const char *msg, size_t msg_len)
285
node_state_update.live = (!rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN));
286
node_state_update.hops = host->system_info->hops;
287
}
288
+ node_state_update.capabilities = aclk_get_node_instance_capas(host);
289
}
290
291
- node_state_update.capabilities = aclk_get_node_instance_capas(host);
292
-
291
rrdhost_aclk_state_lock(localhost);
292
node_state_update.claim_id = localhost->aclk_state.claimed_id;
293
query->data.bin_payload.payload = generate_node_instance_connection(&query->data.bin_payload.size, &node_state_update);
collectors/apps.plugin/apps_plugin.c
+1
@@ -5165,4 +5165,5 @@ int main(int argc, char **argv) {
5165
5166
debug_log("done Loop No %zu", global_iterations_counter);
5167
}
5168
+ netdata_mutex_unlock(&mutex);
5169
}
database/engine/cache.c
+1
-1
@@ -1764,7 +1764,7 @@ PGC *pgc_create(const char *name,
1764
cache->config.max_dirty_pages_per_call = max_dirty_pages_per_flush;
1765
cache->config.pgc_save_init_cb = pgc_save_init_cb;
1766
cache->config.pgc_save_dirty_cb = pgc_save_dirty_cb;
1767
- cache->config.max_pages_per_inline_eviction = (max_pages_per_inline_eviction < 2) ? 2 : max_pages_per_inline_eviction;
1767
+ cache->config.max_pages_per_inline_eviction = max_pages_per_inline_eviction;
1768
cache->config.max_skip_pages_per_inline_eviction = (max_skip_pages_per_inline_eviction < 2) ? 2 : max_skip_pages_per_inline_eviction;
1769
cache->config.max_flushes_inline = (max_flushes_inline < 1) ? 1 : max_flushes_inline;
1770
cache->config.partitions = partitions < 1 ? (size_t)get_netdata_cpus() : partitions;
database/rrdcalc.c
+1
-1
@@ -95,7 +95,7 @@ static STRING *rrdcalc_replace_variables_with_rrdset_labels(const char *line, RR
95
temp = buf;
96
}
97
else if (!strncmp(var, RRDCALC_VAR_LABEL, RRDCALC_VAR_LABEL_LEN)) {
98
- char label_val[RRDCALC_VAR_MAX + 1] = { 0 };
98
+ char label_val[RRDCALC_VAR_MAX + RRDCALC_VAR_LABEL_LEN + 1] = { 0 };
99
strcpy(label_val, var+RRDCALC_VAR_LABEL_LEN);
100
label_val[i - RRDCALC_VAR_LABEL_LEN - 1] = '\0';
101
libnetdata/buffer/buffer.c
+1
@@ -495,6 +495,7 @@ int buffer_unittest(void) {
495
buffer_json_finalize(wb);
496
errors += buffer_expect(wb, "{\n \"hello\":\"world\",\n \"alpha\":\"this: \\\" is a double quote\",\n \"object1\":{\n \"hello\":\"world\"\n }\n}\n");
497
498
+ buffer_free(wb);
499
return errors;
500
}
501
web/api/queries/weights.c
+2
@@ -741,6 +741,8 @@ static size_t spread_results_evenly(DICTIONARY *results, WEIGHTS_STATS *stats) {
741
}
742
dfe_done(t);
743
744
+ if(!dimensions) return 0; // Coverity fix
745
+
746
// sort the array with the values of all dimensions
747
qsort(slots, dimensions, sizeof(NETDATA_DOUBLE), compare_netdata_doubles);
748