All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
@ 2026-11-22 11:48 Zhu Wei
  2026-11-22 11:48 ` [PATCH v2 1/1 ] " Zhu Wei
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Wei @ 2026-11-22 11:48 UTC (permalink / raw)
  To: qemu-devel, qemu-block; +Cc: 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.

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] 4+ messages in thread

* [PATCH v2 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  2026-11-22 11:48 [PATCH v2 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs() Zhu Wei
@ 2026-11-22 11:48 ` Zhu Wei
  2026-11-23 13:28   ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Wei @ 2026-11-22 11:48 UTC (permalink / raw)
  To: qemu-devel, qemu-block; +Cc: 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: fb5458cd10a1 ("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(-)

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)
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  2026-11-22 11:48 ` [PATCH v2 1/1 ] " Zhu Wei
@ 2026-11-23 13:28   ` Eric Blake
  2026-11-23 13:34     ` zhuwei
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2026-11-23 13:28 UTC (permalink / raw)
  To: Zhu Wei; +Cc: qemu-devel, qemu-block, Markus Armbruster, niming, zhuwei

On Sun, Nov 22, 2026 at 07:48:49PM +0800, Zhu Wei wrote:
> 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: fb5458cd10a1 ("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(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  2026-11-23 13:28   ` Eric Blake
@ 2026-11-23 13:34     ` zhuwei
  0 siblings, 0 replies; 4+ messages in thread
From: zhuwei @ 2026-11-23 13:34 UTC (permalink / raw)
  To: Eric Blake, Zhu Wei; +Cc: qemu-devel, qemu-block, Markus Armbruster, niming



On 2026/11/23 21:28, Eric Blake wrote:
> On Sun, Nov 22, 2026 at 07:48:49PM +0800, Zhu Wei wrote:
>> 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: fb5458cd10a1 ("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(-)
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 

Sorry,
the v4 update progress is as follows:
https://lore.kernel.org/qemu-devel/20261123132344.3154080-1-zhuwei@sangfor.com.cn/


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-23 13:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 11:48 [PATCH v2 0/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs() Zhu Wei
2026-11-22 11:48 ` [PATCH v2 1/1 ] " Zhu Wei
2026-11-23 13:28   ` Eric Blake
2026-11-23 13:34     ` zhuwei

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.