* [PATCH v4 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
@ 2026-11-23 13:23 Zhu Wei
2026-11-23 13:23 ` [PATCH v4 1/1 ] " Zhu Wei
0 siblings, 1 reply; 3+ messages in thread
From: Zhu Wei @ 2026-11-23 13:23 UTC (permalink / raw)
To: qemu-devel, qemu-block
Cc: Marc-André Lureau, Markus Armbruster, niming, zhuwei,
zachwade . k
From: zhuwei <zhuwei@sangfor.com.cn>
Hi,
hmp_info_block_jobs() walks the BlockJobInfoList returned by
qmp_query_block_jobs() with a single variable, 'list', which is used both
as the head of the list and as the loop iterator. By the time the loop
terminates 'list' is NULL, so the trailing call to
qapi_free_BlockJobInfoList(list) frees nothing and the full list handed
back by qmp_query_block_jobs() is leaked. Every "info block-jobs" HMP
command run while a job is active (stream, mirror, commit, backup...)
leaks the whole list.
The patch keeps the head of the list in a separate variable ('head') and
frees that one after the loop, so the list is released as intended. No
functional change is expected; it only fixes the leak.
v4:
- Corrected the Fixes: tag to point at the commit that introduced the
leak, "hmp: fix memory leak at hmp_info_block_jobs()"
v3:
- Dropped the redundant comment.
v2:
- Corrected the Fixes: tag to point at the commit that introduced the
leak, "qmp: add query-block-jobs".
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(-)
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v4 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
2026-11-23 13:23 [PATCH v4 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs() Zhu Wei
@ 2026-11-23 13:23 ` Zhu Wei
2026-11-23 13:57 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Zhu Wei @ 2026-11-23 13:23 UTC (permalink / raw)
To: qemu-devel, qemu-block
Cc: Marc-André Lureau, Markus Armbruster, niming, zhuwei,
zachwade . k
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: 93bb1315250d ("hmp: fix memory leak at hmp_info_block_jobs()")
Signed-off-by: niming <niming@sangfor.com.cn>
Signed-off-by: zhuwei <zhuwei@sangfor.com.cn>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
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;
}
+ 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)
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v4 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
2026-11-23 13:23 ` [PATCH v4 1/1 ] " Zhu Wei
@ 2026-11-23 13:57 ` Markus Armbruster
0 siblings, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2026-11-23 13:57 UTC (permalink / raw)
To: Zhu Wei; +Cc: qemu-devel, qemu-block, Marc-André Lureau, niming, zhuwei
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: 93bb1315250d ("hmp: fix memory leak at hmp_info_block_jobs()")
> Signed-off-by: niming <niming@sangfor.com.cn>
> Signed-off-by: zhuwei <zhuwei@sangfor.com.cn>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> 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;
> }
>
> + 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)
Reviewed-by: Markus Armbruster <armbru@redhat.com>
The function right above this one does a similar loop more nicely:
stats_list = qmp_query_blockstats(false, false, NULL);
for (stats = stats_list; stats; stats = stats->next) {
...
}
qapi_free_BlockStatsList(stats_list);
Observation, not a demand.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 13:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 13:23 [PATCH v4 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs() Zhu Wei
2026-11-23 13:23 ` [PATCH v4 1/1 ] " Zhu Wei
2026-11-23 13:57 ` Markus Armbruster
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.