From 7ad6019d165805b12dabb0833f7de0f04dc12182 Mon Sep 17 00:00:00 2001 From: Eric Boyd Date: Mon, 13 Oct 2025 10:12:10 -0500 Subject: [PATCH] Fix overwritten event entries in _webui_new_event_inf When creating new event info data and number, search for an empty event array entry rather than simply increasing the number and potentially overwriting existing info. This prevents intermittent double deletions when event blocking is disabled and many events of varying run durations occur in a short time. Also, increase the number of event entries that can be used to WEBUI_MAX_IDS which is the allocated events variable size. --- src/webui.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/webui.c b/src/webui.c index 861edbe85..d656c31b6 100644 --- a/src/webui.c +++ b/src/webui.c @@ -4804,10 +4804,23 @@ static char* _webui_get_full_path(_webui_window_t* win, const char* file) { static size_t _webui_new_event_inf(_webui_window_t* win, webui_event_inf_t** event_inf) { (*event_inf) = (webui_event_inf_t*)_webui_malloc(sizeof(webui_event_inf_t)); - if (win->events_count > WEBUI_MAX_ARG) - win->events_count = 0; - size_t event_num = win->events_count++; + + size_t event_num = win->events_count; + + // Lock memory and search for next empty event entry + _webui_mutex_lock(&_webui.mutex_mem); + + do { + event_num++; + if (win->events_count >= WEBUI_MAX_IDS) + event_num = 0; + } while (win->events[event_num] != NULL); + + _webui_mutex_unlock(&_webui.mutex_mem); + + win->events_count = event_num; win->events[event_num] = (*event_inf); + return event_num; }