fix coverity (#11535)
Emmanuel Vasilakis committed
Sep 21, 2021 at 14:54 UTC
103d74bbab9faa47a9b2aeb4c604d33b6949c73a
1 file changed
+5
-4
health/health_config.c
+5
-4
@@ -734,7 +734,7 @@ static int health_readfile(const char *filename, void *data) {
734
}
735
else if(hash == hash_os && !strcasecmp(key, HEALTH_OS_KEY)) {
736
char *os_match = value;
737
- alert_cfg->os = strdupz(value);
737
+ if (alert_cfg) alert_cfg->os = strdupz(value);
738
SIMPLE_PATTERN *os_pattern = simple_pattern_create(os_match, NULL, SIMPLE_PATTERN_EXACT);
739
740
if(!simple_pattern_matches(os_pattern, host->os)) {
@@ -751,7 +751,7 @@ static int health_readfile(const char *filename, void *data) {
751
}
752
else if(hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) {
753
char *host_match = value;
754
- alert_cfg->host = strdupz(value);
754
+ if (alert_cfg) alert_cfg->host = strdupz(value);
755
SIMPLE_PATTERN *host_pattern = simple_pattern_create(host_match, NULL, SIMPLE_PATTERN_EXACT);
756
757
if(!simple_pattern_matches(host_pattern, host->hostname)) {
@@ -1226,17 +1226,18 @@ static int health_readfile(const char *filename, void *data) {
1226
//health_add_alarms_loop(host, rc, ignore_this) ;
1227
if(ignore_this || !alert_hash_and_store_config(rc->config_hash_id, alert_cfg) || !rrdcalc_add_alarm_from_config(host, rc)) {
1228
rrdcalc_free(rc);
1229
- alert_config_free(alert_cfg);
1229
}
1230
}
1231
1232
if(rt) {
1233
if(ignore_this || !alert_hash_and_store_config(rt->config_hash_id, alert_cfg) || !rrdcalctemplate_add_template_from_config(host, rt)) {
1234
rrdcalctemplate_free(rt);
1236
- alert_config_free(alert_cfg);
1235
}
1236
}
1237
1238
+ if (alert_cfg)
1239
+ alert_config_free(alert_cfg);
1240
+
1241
fclose(fp);
1242
return 1;
1243
}