From 1e220af616e7f0816eea088e4b695dea573b50b4 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 4 Feb 2024 18:17:41 +0100 Subject: [PATCH] fs: fix incorrect OoM handling in fugue_dir_explore() Non-NULL dp would be returned by alloc failure path despite having been freed. --- src/fs/fugue/fugue_dir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fs/fugue/fugue_dir.c b/src/fs/fugue/fugue_dir.c index 69c9467..b2c1971 100644 --- a/src/fs/fugue/fugue_dir.c +++ b/src/fs/fugue/fugue_dir.c @@ -93,6 +93,8 @@ void *fugue_dir_explore(char const *path) struct BFile_FileInfo info; char *wildcard=NULL; uint16_t *fc_path=NULL, *search=NULL; + /* We allocate by batches of 8 */ + int sd=-1, rc, allocated=0; dir_t *dp = malloc(sizeof *dp); if(!dp) goto alloc_failure; @@ -100,8 +102,6 @@ void *fugue_dir_explore(char const *path) dp->count = 0; dp->entries = NULL; dp->pos = 0; - /* We allocate by batches of 8 */ - int sd=-1, rc, allocated=0; fc_path = malloc(512 * sizeof *fc_path); if(!fc_path) goto alloc_failure; @@ -149,6 +149,7 @@ void *fugue_dir_explore(char const *path) alloc_failure: errno = ENOMEM; fugue_dir_close(dp); + dp = NULL; end: free(wildcard); free(search);