@cryptotaxi247 / netdata-1 / commits / 000884005

Fix health crash (#15209)

Stelios Fragkakis committed Jun 16, 2023 at 16:24 UTC 000884005ac9dabba6ba9445eae62f86350f614c
1 file changed +14 -9
health/health.c
+14 -9
@@ -628,8 +628,9 @@ static inline void health_alarm_log_process(RRDHOST *host) {
628 //delete those that are updated, no in progress execution, and is not repeating
629 netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
630
631 - ALARM_ENTRY *prev = host->health_log.alarms;
632 - for(ae = host->health_log.alarms; ae ; ae = ae->next) {
631 + ALARM_ENTRY *prev = NULL, *next = NULL;
632 + for(ae = host->health_log.alarms; ae ; ae = next) {
633 + next = ae->next; // set it here, for the next iteration
634
635 if((likely(!(ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING)) &&
636 (ae->flags & HEALTH_ENTRY_FLAG_UPDATED) &&
@@ -641,15 +642,19 @@ static inline void health_alarm_log_process(RRDHOST *host) {
642 (ae->when + 3600 < now_realtime_sec())))
643 {
644
644 - if (ae == host->health_log.alarms) {
645 - host->health_log.alarms = ae->next;
646 - prev = ae->next;
647 - } else {
648 - prev->next = ae->next;
645 + if(host->health_log.alarms == ae) {
646 + host->health_log.alarms = next;
647 + // prev is also NULL here
648 + }
649 + else {
650 + prev->next = next;
651 + // prev should not be touched here - we need it for the next iteration
652 + // because we may have to also remove the next item
653 }
654 +
655 health_alarm_log_free_one_nochecks_nounlink(ae);
651 - ae = prev;
652 - } else
656 + }
657 + else
658 prev = ae;
659 }
660