summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-10-02 06:58:00 +0200
committerTom Rini <trini@konsulko.com>2018-10-06 14:09:41 -0400
commit0d532e911cb7e67e151153289024183bc4f5b257 (patch)
treecf3b415d7eb6ded438a95e1d16a2bfa2095eb0b0 /fs
parent46580f2fd569946f711af63002e2628b9ff109e3 (diff)
fs: fat: memory leak in fat_unlink()
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat_write.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index fc211e74bc..1ec72d156b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -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);