Commit 464b1c1
slab: fix memory leak when refill_sheaf() fails
When refill_sheaf() partially fills one sheaf (e.g., fills 5 objects
but need to fill 10), it will update sheaf->size and return -ENOMEM.
However, the callers (alloc_full_sheaf() and __pcs_replace_empty_main())
directly call free_empty_sheaf() on failure, which only does kfree(sheaf),
causing the partially allocated objects memory in sheaf->objects[] leaked.
Fix this by calling sheaf_flush_unused() before free_empty_sheaf() to
free objects of sheaf->objects[]. And also add a WARN_ON() in
free_empty_sheaf() to catch any future cases where a non-empty sheaf is
being freed.
Fixes: ed30c4a ("slab: add optimized sheaf refill from partial list")
Signed-off-by: Qing Wang <wangqing7171@gmail.com>
Link: https://patch.msgid.link/20260311093617.4155965-1-wangqing7171@gmail.com
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Hao Li <hao.li@linux.dev>
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>1 parent 8dafa9f commit 464b1c1
1 file changed
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2790 | 2790 | | |
2791 | 2791 | | |
2792 | 2792 | | |
| 2793 | + | |
2793 | 2794 | | |
2794 | 2795 | | |
2795 | 2796 | | |
| |||
2821 | 2822 | | |
2822 | 2823 | | |
2823 | 2824 | | |
| 2825 | + | |
2824 | 2826 | | |
2825 | 2827 | | |
2826 | 2828 | | |
| |||
2830 | 2832 | | |
2831 | 2833 | | |
2832 | 2834 | | |
| 2835 | + | |
2833 | 2836 | | |
2834 | 2837 | | |
2835 | 2838 | | |
| |||
4616 | 4619 | | |
4617 | 4620 | | |
4618 | 4621 | | |
| 4622 | + | |
4619 | 4623 | | |
4620 | 4624 | | |
4621 | 4625 | | |
| |||
0 commit comments