hfs: fix a memleak in hfs_find_init
Subsystems (2)
PATCH v2 1/1 hfs: fix a memleak in hfs_find_init
In every caller of hfs_find_init, ptr won't be freed when hfs_find_init fails, but will be freed when somewhere after hfs_find_init fails. This suggests that hfs_find_init should proberly free ptr in its own error-handling to prevent ptr from leaking.
In particular, When the switch statment goes to default and return an error, ptr should be freed.
---
Changelog:
v2: Improve commit message to be more clear.
--- fs/hfs/bfind.c | 1 + 1 file changed, 1 insertion(+)
fs/hfs/bfind.c +1 -0
@@ -36,6 +36,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)mutex_lock_nested (&tree->tree_lock,ATTR_BTREE_MUTEX );break ;default : +kfree (fd->search_key);return -EINVAL ; }return 0 ;
Signature · 1 line
2.34.1
Viacheslav Dubeyko
maintainerQuoted 6 lines · Zhipeng Lu
In every caller of
hfs_find_init,ptrwon't be freed whenhfs_find_initfails, but will be freed when somewhere afterhfs_find_initfails.
Current statement sounds confusing for my taste. I don’t follow it. What do you mean here?
Quoted 2 lines
This suggests that
hfs_find_initshould proberly freeptrin its own error-handling to preventptrfrom leaking.
I assume you meant properly here?
Quoted 3 lines
In particular, When the switch statment goes to default and return an error,
ptrshould be freed.
I assume you meant statement here?
Also, you mentioning ptr but we freed fd->search_key here. It sounds confusing too.
Quoted 7 lines
Fixes b3b2177a2d79 ("hfs: add lock nesting notation to hfs_find_init")Signed-off-by Zhipeng Lu <[email protected]>---
Changelog:v2: Improve commit message to be more clear.
Currently, it sounds slightly more confusing. :)
Thanks,
Slava.
Quoted 19 lines
---
fs/hfs/bfind.c| 1 +1 file changed, 1 insertion(+)fs/hfs/bfind.c +0
-0@@ -36,6 +36,7 @@ int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)mutex_lock_nested (&tree->tree_lock,ATTR_BTREE_MUTEX );break ;default:
+kfree(fd->search_key);
return-EINVAL;
}
return 0;Signature · 1 line
2.34.1