From b6b5edf13b5d3500c94a5afc7adda132768cd568 Mon Sep 17 00:00:00 2001 From: Evgeniy Naydanov Date: Fri, 14 Feb 2025 19:30:55 +0300 Subject: [PATCH] rtos/linux: handle OOM in `linux_gdb_thread_packet()` Return an error in case `calloc()` fails. Change-Id: Id1b758a1edbae3d71d625d1992579b99720d77d6 Signed-off-by: Evgeniy Naydanov Reviewed-on: https://review.openocd.org/c/openocd/+/8762 Tested-by: jenkins Reviewed-by: zapb --- src/rtos/linux.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rtos/linux.c b/src/rtos/linux.c index 5467988f3..91d9a39f2 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -1040,6 +1040,10 @@ static int linux_gdb_thread_packet(struct target *target, return ERROR_TARGET_FAILURE; char *out_str = calloc(MAX_THREADS * 17 + 10, 1); + if (!out_str) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } char *tmp_str = out_str; tmp_str += sprintf(tmp_str, "m"); struct threads *temp = linux_os->thread_list; -- 2.49.0