[U-Boot] [PATCH 1/1] fs: fat: memory leak in fat_unlink()
AKASHI Takahiro
takahiro.akashi at linaro.org
Tue Oct 2 06:39:54 UTC 2018
On Tue, Oct 02, 2018 at 06:58:00AM +0200, Heinrich Schuchardt wrote:
> Do not leak filename_copy in case of error.
> Catch out of memory when calling strdup.
>
> This addresses Coverity Scan CID 184086.
Thanks,
-Takahiro Akashi
> Reported-by: Tom Rini <trini at konsulko.com>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
> fs/fat/fat_write.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index 4286a0a847..b1ed0e6734 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -1263,6 +1263,11 @@ int fat_unlink(const char *filename)
> char *filename_copy, *dirname, *basename;
>
> filename_copy = strdup(filename);
> + if (!filename_copy) {
> + printf("Error: allocating memory\n");
> + ret = -ENOMEM;
> + goto exit;
> + }
> split_filename(filename_copy, &dirname, &basename);
>
> if (!strcmp(dirname, "/") && !strcmp(basename, "")) {
> @@ -1274,7 +1279,8 @@ int fat_unlink(const char *filename)
> itr = malloc_cache_aligned(sizeof(fat_itr));
> if (!itr) {
> printf("Error: allocating memory\n");
> - return -ENOMEM;
> + ret = -ENOMEM;
> + goto exit;
> }
>
> ret = fat_itr_root(itr, &fsdata);
> --
> 2.19.0
>
More information about the U-Boot
mailing list