From f9ac258b9ee09b5e4aec7aa0c47b4c2149da47b4 Mon Sep 17 00:00:00 2001 From: bl4ckhyun Date: Mon, 13 Apr 2026 14:34:00 +0900 Subject: [PATCH 1/3] [lib][libc] Fix fclose condition for fs-backed streams --- lib/libc/stdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/stdio.c b/lib/libc/stdio.c index 03051fe3b2..65166dcd9b 100644 --- a/lib/libc/stdio.c +++ b/lib/libc/stdio.c @@ -73,7 +73,7 @@ FILE *fopen(const char *filename, const char *mode) { int fclose(FILE *stream) { #if defined(WITH_LIB_FS) - if (stream && !stream->use_fs) { + if (stream && stream->use_fs) { fs_close_file(stream->fs_handle.handle); free(stream); } From 4375e93cc9cfac0b16ebe15f5eaedbe00394f6c0 Mon Sep 17 00:00:00 2001 From: bl4ckhyun Date: Mon, 13 Apr 2026 14:59:57 +0900 Subject: [PATCH 2/3] [lib][fs] Fix cleanup on handle allocation failure --- lib/fs/fs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/fs/fs.c b/lib/fs/fs.c index 441d3795be..58a88f4529 100644 --- a/lib/fs/fs.c +++ b/lib/fs/fs.c @@ -266,6 +266,11 @@ status_t fs_open_file(const char *path, filehandle **handle) { } filehandle *f = malloc(sizeof(*f)); + if (!f) { + mount->api->close(cookie); + put_mount(mount); + return ERR_NO_MEMORY; + } f->cookie = cookie; f->mount = mount; *handle = f; @@ -309,8 +314,9 @@ status_t fs_create_file(const char *path, filehandle **handle, uint64_t len) { filehandle *f = malloc(sizeof(*f)); if (!f) { + mount->api->close(cookie); put_mount(mount); - return err; + return ERR_NO_MEMORY; } f->cookie = cookie; f->mount = mount; @@ -425,6 +431,7 @@ status_t fs_open_dir(const char *path, dirhandle **handle) { dirhandle *d = malloc(sizeof(*d)); if (!d) { + mount->api->closedir(cookie); put_mount(mount); return ERR_NO_MEMORY; } From 518a10db3340a7ddd9d53ea534d35b5ec5f108d5 Mon Sep 17 00:00:00 2001 From: bl4ckhyun Date: Mon, 13 Apr 2026 15:07:24 +0900 Subject: [PATCH 3/3] [platform][zynq] Check for CFI buffer allocation failure --- platform/zynq/spiflash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/zynq/spiflash.c b/platform/zynq/spiflash.c index cce61d897b..dabc2993a0 100644 --- a/platform/zynq/spiflash.c +++ b/platform/zynq/spiflash.c @@ -207,6 +207,10 @@ status_t spiflash_detect(void) { /* read and parse the cfi */ uint8_t *buf = calloc(1, 512); + if (!buf) { + flash.detected = false; + return ERR_NO_MEMORY; + } ssize_t len = spiflash_read_cfi(buf, 512); if (len < 4) goto nodetect;