From 9abec302a4736c965a34b930f4f5bf2b1494bf6e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 27 Jun 2023 20:46:10 +0200 Subject: Adding upstream version 1.40.1. Signed-off-by: Daniel Baumann --- health/health.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'health') diff --git a/health/health.c b/health/health.c index df4798a20..e04debb93 100644 --- a/health/health.c +++ b/health/health.c @@ -628,8 +628,9 @@ static inline void health_alarm_log_process(RRDHOST *host) { //delete those that are updated, no in progress execution, and is not repeating netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock); - ALARM_ENTRY *prev = host->health_log.alarms; - for(ae = host->health_log.alarms; ae ; ae = ae->next) { + ALARM_ENTRY *prev = NULL, *next = NULL; + for(ae = host->health_log.alarms; ae ; ae = next) { + next = ae->next; // set it here, for the next iteration if((likely(!(ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING)) && (ae->flags & HEALTH_ENTRY_FLAG_UPDATED) && @@ -641,15 +642,19 @@ static inline void health_alarm_log_process(RRDHOST *host) { (ae->when + 3600 < now_realtime_sec()))) { - if (ae == host->health_log.alarms) { - host->health_log.alarms = ae->next; - prev = ae->next; - } else { - prev->next = ae->next; + if(host->health_log.alarms == ae) { + host->health_log.alarms = next; + // prev is also NULL here + } + else { + prev->next = next; + // prev should not be touched here - we need it for the next iteration + // because we may have to also remove the next item } + health_alarm_log_free_one_nochecks_nounlink(ae); - ae = prev; - } else + } + else prev = ae; } -- cgit v1.2.3