fs: fat: Fix possible double free of fatbuf

fat_itr_root() allocates fatbuf so we free it on the exit path, if
the function fails we should not free it, check the return value
and skip freeing if the function fails.

Signed-off-by: Andrew F. Davis <afd@ti.com>
This commit is contained in:
Andrew F. Davis authored and Tom Rini committed 2019-05-28 13:57:52 -04:00
1 parent 7b437807ee
commit d0cd30eb81
1 file changed
+5 -4
+5 -4
View File
@@ -1134,11 +1134,12 @@ int fat_size(const char *filename, loff_t *size)
* expected to fail if passed a directory path:
*/
free(fsdata.fatbuf);
fat_itr_root(itr, &fsdata);
if (!fat_itr_resolve(itr, filename, TYPE_DIR)) {
ret = fat_itr_root(itr, &fsdata);
if (ret)
goto out_free_itr;
ret = fat_itr_resolve(itr, filename, TYPE_DIR);
if (!ret)
*size = 0;
ret = 0;
}
goto out_free_both;
}