Skip to content

Commit

Permalink
fs: ext4: correct error handling
Browse files Browse the repository at this point in the history
After calling strdup() check the returned pointer.

Avoid a memory leak if the directory is not found.

Reported-by: Michael Nazzareno Trimarchi <[email protected]>
Fixes: 22fdac3 ("fs: ext4: implement opendir, readdir, closedir")
Signed-off-by: Heinrich Schuchardt <[email protected]>
Reviewed-by: Ilias Apalodimas <[email protected]>
  • Loading branch information
xypron authored and trini committed Nov 13, 2024
1 parent bbc3d12 commit 9084e1b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/ext4/ext4fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
if (!dirs)
return -ENOMEM;
dirs->dirname = strdup(dirname);
if (!dirs) {
if (!dirs->dirname) {
free(dirs);
return -ENOMEM;
}
Expand All @@ -224,6 +224,8 @@ int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
ret = 0;
*dirsp = (struct fs_dir_stream *)dirs;
} else {
free(dirs->dirname);
free(dirs);
ret = -ENOENT;
}

Expand Down

0 comments on commit 9084e1b

Please sign in to comment.