[PATCH OLK-6.6] bpf-rvi: block: fix memleak issue in bpf_show_partitions_start()
 
            hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICA1GK -------------------------------- Fix memleak issue by cleaning up entries in xarry after the function ends. Fixes: cafddc3c1c41 ("bpf-rvi: block: Look up /dev in reaper's fs->root and filter partitions") Signed-off-by: Gu Bowen <gubowen5@huawei.com> --- block/bpf-rvi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block/bpf-rvi.c b/block/bpf-rvi.c index 1c1aaa778445..8050fddebad2 100644 --- a/block/bpf-rvi.c +++ b/block/bpf-rvi.c @@ -353,6 +353,20 @@ static void *bpf_show_partitions_start(struct seq_file *seqf, loff_t *pos) return p; } +static void bpf_show_partitions_stop(struct seq_file *seqf, void *v) +{ + struct block_device *entry; + struct partitions_seq_priv *priv = seqf->private; + unsigned long index; + + bpf_disk_seqf_stop(seqf, v); + + xa_for_each(&priv->dev_list, index, entry) { + xa_erase(&priv->dev_list, index); + kfree(entry); + } +} + struct bpf_iter__partitions { __bpf_md_ptr(struct bpf_iter_meta *, meta); __bpf_md_ptr(struct block_device *, part); @@ -410,7 +424,7 @@ static int bpf_show_partitions(struct seq_file *seqf, void *v) static const struct seq_operations bpf_partitions_op = { .start = bpf_show_partitions_start, .next = bpf_disk_seqf_next, - .stop = bpf_disk_seqf_stop, + .stop = bpf_show_partitions_stop, .show = bpf_show_partitions }; -- 2.43.0
 
            反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/18666 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/QEE... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/18666 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/QEE...
participants (2)
- 
                 Gu Bowen Gu Bowen
- 
                 patchwork bot patchwork bot