hfs: fix a memleak in hfs_find_init
Subsystems (2)
PATCH v3 1/1 hfs: fix a memleak in hfs_find_init
If hfs_find_init succeeds but some other function called after it fails, the overall cleanup function of hfs_find_init (i.e. hfs_find_exit) will be called and fd->search_key is freed. However, if hfs_find_init fails and returns an error, neither external nor internal deallocation of fd->search_key is triggered.
This observation suggests that there could be a memleak problem in hfs_find_init. In this patch, we add the missing deallocation in the error-handling path (i.e. the default branch of the switch statement) to prevent such memory leak.
---
Changelog:
v2: Improve commit message to be more clear.
v3: Update commit message.
--- 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
Quoted 15 lines · Zhipeng Lu
If
hfs_find_initsucceeds but some other function called after it fails, the overall cleanup function ofhfs_find_init(i.e.hfs_find_exit) will be called andfd->search_keyis freed. However, ifhfs_find_initfails and returns an error, neither external nor internal deallocation offd->search_keyis triggered.This observation suggests that there could be a memleak problem in
hfs_find_init. In this patch, we add the missing deallocation in the error-handling path (i.e. the default branch of the switch statement) to prevent such memory leak.
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.
v3: Update commit message.
Looks good. Thanks a lot for reworking the comment section.
Thanks,
Slava.
Quoted 19 lines
---
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