Skip to content

Commit dae93fe

Browse files
committed
Fix endless recursion on webui_malloc in debug mode.
We're sure the length of the debug message of _webui_malloc < 256, so in that case we have enough room to print the debug message without allocating memory with _webui_malloc, which prevents an endless recursion to _webui_log. Signed-off-by: Hans Dijkema <hans@dijkewijk.nl>
1 parent 2a9c91c commit dae93fe

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/webui.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,16 @@ static void _webui_log(size_t level, const char *format, va_list args) {
727727
_webui.logger_func(WEBUI_LOGGER_LEVEL_ERROR, "Log formatting error", _webui.logger_user_data);
728728
return;
729729
}
730-
char *buffer = _webui_malloc(needed_size + 1);
730+
731+
char buf[256];
732+
char *buffer = (needed_size > 255) ? _webui_malloc(needed_size + 1) : buf;
731733
if (buffer == NULL) {
732734
_webui.logger_func(WEBUI_LOGGER_LEVEL_ERROR, "Memory allocation failed for log", _webui.logger_user_data);
733735
return;
734736
}
735737
vsnprintf(buffer, needed_size + 1, format, args);
736738
_webui.logger_func(level, buffer, _webui.logger_user_data);
737-
_webui_free_mem((void*)buffer);
739+
if (buffer != buf) _webui_free_mem((void*)buffer);
738740
}
739741
}
740742

0 commit comments

Comments
 (0)