Skip to content

Commit

Permalink
ipc: fix memory leak in init_mqueue_fs()
Browse files Browse the repository at this point in the history
When setup_mq_sysctls() failed in init_mqueue_fs(), mqueue_inode_cachep is
not released.  In order to fix this issue, the release path is reordered.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: dc55e35 ("ipc: Store mqueue sysctls in the ipc namespace")
Signed-off-by: Zhengchao Shao <[email protected]>
Cc: Alexey Gladkov <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Jingyu Wang <[email protected]>
Cc: Muchun Song <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Waiman Long <[email protected]>
Cc: Wei Yongjun <[email protected]>
Cc: YueHaibing <[email protected]>
Cc: Yu Zhe <[email protected]>
Cc: Manfred Spraul <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
zhengchaoshao authored and akpm00 committed Dec 12, 2022
1 parent 9f2b5de commit 12b677f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ipc/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ static int __init init_mqueue_fs(void)

if (!setup_mq_sysctls(&init_ipc_ns)) {
pr_warn("sysctl registration failed\n");
return -ENOMEM;
error = -ENOMEM;
goto out_kmem;
}

error = register_filesystem(&mqueue_fs_type);
Expand All @@ -1744,8 +1745,9 @@ static int __init init_mqueue_fs(void)
out_filesystem:
unregister_filesystem(&mqueue_fs_type);
out_sysctl:
kmem_cache_destroy(mqueue_inode_cachep);
retire_mq_sysctls(&init_ipc_ns);
out_kmem:
kmem_cache_destroy(mqueue_inode_cachep);
return error;
}

Expand Down

0 comments on commit 12b677f

Please sign in to comment.