From: Heinrich Schuchardt Date: Thu, 7 Nov 2024 09:38:53 +0000 (+0100) Subject: fs: ext4: correct error handling X-Git-Url: http://git.dujemihanovic.xyz/html/static/git-favicon.png?a=commitdiff_plain;h=9084e1b1b94c31d76ae7efd12f8828f3b4ed2255;p=u-boot.git fs: ext4: correct error handling After calling strdup() check the returned pointer. Avoid a memory leak if the directory is not found. Reported-by: Michael Nazzareno Trimarchi Fixes: 22fdac381f98 ("fs: ext4: implement opendir, readdir, closedir") Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index dfecfa0b4e..1727da2dc6 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -213,7 +213,7 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp) if (!dirs) return -ENOMEM; dirs->dirname = strdup(dirname); - if (!dirs) { + if (!dirs->dirname) { free(dirs); return -ENOMEM; } @@ -224,6 +224,8 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp) ret = 0; *dirsp = (struct fs_dir_stream *)dirs; } else { + free(dirs->dirname); + free(dirs); ret = -ENOENT; }