]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs: fat: memory leak in fat_unlink()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 2 Oct 2018 04:58:00 +0000 (06:58 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 6 Oct 2018 18:09:41 +0000 (14:09 -0400)
Do not leak filename_copy in case of error.
Catch out of memory when calling strdup.

Reported-by: Coverity (CID: 184086)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
fs/fat/fat_write.c

index fc211e74bc69ef71c5c262778b70eb094f8c4da0..1ec72d156b02c04b250a97927219674342abaa2f 100644 (file)
@@ -1259,6 +1259,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, "")) {
@@ -1270,7 +1275,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);