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

Reported-by: niming <niming@sangfor.com.cn>
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 1/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  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 ` Zhu Wei
  2026-11-17 18:07   ` Markus Armbruster
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu Wei @ 2026-11-17 14:45 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: Kevin Wolf, Hanna Reitz, 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: 2bcad73c4b9b ("monitor/hmp: move hmp_info_block* to block-hmp-cmds.c")
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 1/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  2026-11-17 14:45 ` [PATCH 1/1] " Zhu Wei
@ 2026-11-17 18:07   ` Markus Armbruster
  2026-11-18  1:09     ` zhuwei
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2026-11-17 18:07 UTC (permalink / raw)
  To: Zhu Wei; +Cc: qemu-devel, qemu-block, Kevin Wolf, Hanna Reitz, 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: 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.


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

* Re: [PATCH 1/1] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
  2026-11-17 18:07   ` Markus Armbruster
@ 2026-11-18  1:09     ` zhuwei
  0 siblings, 0 replies; 4+ messages in thread
From: zhuwei @ 2026-11-18  1:09 UTC (permalink / raw)
  To: Markus Armbruster, Zhu Wei
  Cc: qemu-devel, qemu-block, Kevin Wolf, Hanna Reitz, niming



On 2026/11/18 2:07, Markus Armbruster wrote:
> 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.
> 
I'd be glad to.


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

end of thread, other threads:[~2026-11-18  1:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-18  1:09     ` 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.