From: Francois Berder Date: Mon, 19 Jan 2026 14:49:06 +0000 (+0100) Subject: tools: Handle realloc failure in strlist_add X-Git-Tag: v2026.04-rc2~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a53a03f50118e329a0f38bd28ea5f7d8e22147a;p=thirdparty%2Fu-boot.git tools: Handle realloc failure in strlist_add If realloc fails, list->strings was set to NULL and it would create a leak. This commit ensures that if we cannot add a string to the list, the list stays in a good state. Signed-off-by: Francois Berder --- diff --git a/tools/image-host.c b/tools/image-host.c index 54df86316ae..48d69191c92 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -733,6 +733,7 @@ static void strlist_free(struct strlist *list) static int strlist_add(struct strlist *list, const char *str) { char *dup; + char **tmp = NULL; if (!list || !str) return -1; @@ -741,13 +742,13 @@ static int strlist_add(struct strlist *list, const char *str) if(!dup) return -1; - list->strings = realloc(list->strings, - (list->count + 1) * sizeof(char *)); - if (!list->strings) { + tmp = realloc(list->strings, (list->count + 1) * sizeof(char *)); + if (!tmp) { free(dup); return -1; } + list->strings = tmp; list->strings[list->count++] = dup; return 0;