Skip to content

Commit

Permalink
fs: fat: memory leak in fat_unlink()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xypron authored and trini committed Oct 6, 2018
1 parent 46580f2 commit 0d532e9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fs/fat/fat_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")) {
Expand All @@ -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);
Expand Down

0 comments on commit 0d532e9

Please sign in to comment.