Skip to content

Commit 7ad6019

Browse files
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.
1 parent dcc776a commit 7ad6019

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/webui.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4804,10 +4804,23 @@ static char* _webui_get_full_path(_webui_window_t* win, const char* file) {
48044804

48054805
static size_t _webui_new_event_inf(_webui_window_t* win, webui_event_inf_t** event_inf) {
48064806
(*event_inf) = (webui_event_inf_t*)_webui_malloc(sizeof(webui_event_inf_t));
4807-
if (win->events_count > WEBUI_MAX_ARG)
4808-
win->events_count = 0;
4809-
size_t event_num = win->events_count++;
4807+
4808+
size_t event_num = win->events_count;
4809+
4810+
// Lock memory and search for next empty event entry
4811+
_webui_mutex_lock(&_webui.mutex_mem);
4812+
4813+
do {
4814+
event_num++;
4815+
if (win->events_count >= WEBUI_MAX_IDS)
4816+
event_num = 0;
4817+
} while (win->events[event_num] != NULL);
4818+
4819+
_webui_mutex_unlock(&_webui.mutex_mem);
4820+
4821+
win->events_count = event_num;
48104822
win->events[event_num] = (*event_inf);
4823+
48114824
return event_num;
48124825
}
48134826

0 commit comments

Comments
 (0)