Fix coverity issues (#15345)
* sensor_name always has a value -- CID 395493: Control flow issues (DEADCODE) * Check fopen failure -- CID 395492: Null pointer dereferences (NULL_RETURNS) * CID 395491: Control flow issues (DEADCODE) * sel_count will be >=0 in this case -- CID 395490: Control flow issues (DEADCODE) * Memory leak -- CID 395487: Resource leaks (RESOURCE_LEAK)
Stelios Fragkakis committed
Jul 11, 2023 at 12:32 UTC
75ecb70175a778a8a389307b0048cf8fd53c5064
3 files changed
+8
-6
collectors/freeipmi.plugin/freeipmi_plugin.c
+3
-3
@@ -518,7 +518,7 @@ static int netdata_get_ipmi_sel_events_count(struct ipmi_monitoring_ipmi_config
518
goto cleanup;
519
}
520
521
- netdata_update_ipmi_sel_events_count(state, sel_count >= 0 ? sel_count : 0);
521
+ netdata_update_ipmi_sel_events_count(state, sel_count);
522
523
rv = 0;
524
@@ -972,7 +972,7 @@ static void netdata_update_ipmi_sensor_reading(
972
.sensor_state = sensor_state,
973
.sensor_units = sensor_units,
974
.sensor_reading_type = sensor_reading_type,
975
- .sensor_name = strdupz(sensor_name ? sensor_name : ""),
975
+ .sensor_name = strdupz(sensor_name),
976
.component = netdata_sensor_name_to_component(sensor_name),
977
.do_state = !excluded_state,
978
.do_metric = !excluded_metric,
@@ -1245,7 +1245,7 @@ void *netdata_ipmi_collection_thread(void *ptr) {
1245
t->state.sel.last_iteration_ut = 0;
1246
}
1247
1248
- return ptr;
1248
+ break;
1249
}
1250
1251
spinlock_lock(&t->spinlock);
registry/registry_init.c
+2
@@ -48,6 +48,8 @@ void registry_db_stats(void) {
48
49
void registry_generate_curl_urls(void) {
50
FILE *fp = fopen("/tmp/registry.curl", "w+");
51
+ if (unlikely(!fp))
52
+ return;
53
54
REGISTRY_PERSON *p;
55
dfe_start_read(registry.persons, p) {
web/api/web_api_v2.c
+3
-3
@@ -103,11 +103,11 @@ static bool verify_agent_uuids(const char *machine_guid, const char *node_id, co
103
return false;
104
105
char *agent_claim_id = get_agent_claimid();
106
- if(!agent_claim_id || strcmp(claim_id, agent_claim_id) != 0)
107
- return false;
106
+
107
+ bool not_verified = (!agent_claim_id || strcmp(claim_id, agent_claim_id) != 0);
108
freez(agent_claim_id);
109
110
- if(!localhost->node_id)
110
+ if(not_verified || !localhost->node_id)
111
return false;
112
113
char buf[UUID_STR_LEN];