From 124690270d8ca89276401fe08a6e136922f54576 Mon Sep 17 00:00:00 2001 From: shuhua hua Date: Fri, 25 Sep 2026 02:05:33 +0000 Subject: [PATCH] shell: flashdev: close fds on allocation failure --- cpukit/libmisc/shell/main_flashdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index 3933e718e5..d55ffae89a 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -312,7 +312,12 @@ int flashdev_shell_write( /* Create buffer */ buffer = calloc(1, 0x1000); - + if (buffer == NULL) { + close(flash); + close(file); + printf("Failed to allocate write buffer\n"); + return -1; + } /* Write file to flash device in 0x1000 byte chunks */ offset = 0; while (offset != length) {