From: Markus Armbruster <armbru@pond.sub.org>
To: Zhu Wei <zachwade.k@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
niming <niming@sangfor.com.cn>, zhuwei <zhuwei@sangfor.com.cn>
Subject: Re: [PATCH 1/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
Date: Tue, 17 Nov 2026 19:07:21 +0100 [thread overview]
Message-ID: <8733szjpra.fsf@pond.sub.org> (raw)
In-Reply-To: <20261117144548.3252867-2-zhuwei@sangfor.com.cn> (Zhu Wei's message of "Tue, 17 Nov 2026 22:45:48 +0800")
Zhu Wei <zachwade.k@gmail.com> writes:
> From: zhuwei <zhuwei@sangfor.com.cn>
>
> hmp_info_block_jobs() uses 'list' both as the head of the BlockJobInfoList
> returned by qmp_query_block_jobs() and as the iterator of the while loop.
> Once the loop finishes, 'list' is NULL, so the call to
> qapi_free_BlockJobInfoList(list) at the end of the function frees nothing
> and the whole list returned by qmp_query_block_jobs() is leaked.
>
> Keep the head of the list in a separate variable and free that one after
> the loop, so the entire list is released as intended.
>
> Fixes: 2bcad73c4b9b ("monitor/hmp: move hmp_info_block* to block-hmp-cmds.c")
Pure code motion. Please try again :)
> Signed-off-by: niming <niming@sangfor.com.cn>
> Signed-off-by: zhuwei <zhuwei@sangfor.com.cn>
> ---
> block/monitor/block-hmp-cmds.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
> index 7bae4d425c..d3f404146a 100644
> --- a/block/monitor/block-hmp-cmds.c
> +++ b/block/monitor/block-hmp-cmds.c
> @@ -760,7 +760,7 @@ void hmp_info_blockstats(MonitorHMP *hmp, const QDict *qdict)
>
> void hmp_info_block_jobs(MonitorHMP *hmp, const QDict *qdict)
> {
> - BlockJobInfoList *list;
> + BlockJobInfoList *list, *head;
>
> list = qmp_query_block_jobs(&error_abort);
>
> @@ -769,6 +769,9 @@ void hmp_info_block_jobs(MonitorHMP *hmp, const QDict *qdict)
> return;
> }
>
> + /* Keep the head: list is NULL once the loop below is done */
> + head = list;
> +
> while (list) {
> if (list->value->type == JOB_TYPE_STREAM) {
> monitor_hmp_printf(hmp, "Streaming device %s: Completed %" PRId64
> @@ -791,7 +794,7 @@ void hmp_info_block_jobs(MonitorHMP *hmp, const QDict *qdict)
> list = list->next;
> }
>
> - qapi_free_BlockJobInfoList(list);
> + qapi_free_BlockJobInfoList(head);
> }
>
> void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
Patch looks good to me, but I'd drop the comment.
next prev parent reply other threads:[~2026-11-17 18:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:45 [PATCH 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs() Zhu Wei
2026-11-17 14:45 ` [PATCH 1/1] " Zhu Wei
2026-11-17 18:07 ` Markus Armbruster [this message]
2026-11-18 1:09 ` zhuwei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8733szjpra.fsf@pond.sub.org \
--to=armbru@pond.sub.org \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=niming@sangfor.com.cn \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=zachwade.k@gmail.com \
--cc=zhuwei@sangfor.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.