]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs: ext4: correct error handling
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 7 Nov 2024 09:38:53 +0000 (10:38 +0100)
committerTom Rini <trini@konsulko.com>
Wed, 13 Nov 2024 14:18:50 +0000 (08:18 -0600)
After calling strdup() check the returned pointer.

Avoid a memory leak if the directory is not found.

Reported-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com>
Fixes: 22fdac381f98 ("fs: ext4: implement opendir, readdir, closedir")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
fs/ext4/ext4fs.c

index dfecfa0b4e8849ed99dc134e8ac8b73c0da999d4..1727da2dc6db089b1d5805be156f5ade5d7c0afa 100644 (file)
@@ -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;
        }