mirror of
https://github.com/smaeul/u-boot.git
synced 2025-10-14 04:46:01 +01:00
fs: ext4: correct error handling
After calling strdup() check the returned pointer. Avoid a memory leak if the directory is not found. Reported-by: Michael Nazzareno Trimarchi <michael@amarulasolutions.com> Fixes: 22fdac381f98 ("fs: ext4: implement opendir, readdir, closedir") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
parent
bbc3d12516
commit
9084e1b1b9
@ -213,7 +213,7 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
|
|||||||
if (!dirs)
|
if (!dirs)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
dirs->dirname = strdup(dirname);
|
dirs->dirname = strdup(dirname);
|
||||||
if (!dirs) {
|
if (!dirs->dirname) {
|
||||||
free(dirs);
|
free(dirs);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
@ -224,6 +224,8 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
*dirsp = (struct fs_dir_stream *)dirs;
|
*dirsp = (struct fs_dir_stream *)dirs;
|
||||||
} else {
|
} else {
|
||||||
|
free(dirs->dirname);
|
||||||
|
free(dirs);
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user