[PATCH 1/1] fs: ext4: correct error handling
Ilias Apalodimas
ilias.apalodimas at linaro.org
Fri Nov 8 12:41:15 CET 2024
On Thu, 7 Nov 2024 at 09:39, Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> After calling strdup() check the returned pointer.
>
> Avoid a memory leak if the directory is not found.
>
> Reported-by: Michael Nazzareno Trimarchi <michael at amarulasolutions.com>
> Fixes: 22fdac381f98 ("fs: ext4: implement opendir, readdir, closedir")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> fs/ext4/ext4fs.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
> index dfecfa0b4e8..1727da2dc6d 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;
> }
>
> --
> 2.45.2
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
More information about the U-Boot
mailing list