All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@pond.sub.org>
To: Zhu Wei <zachwade.k@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	niming <niming@sangfor.com.cn>, zhuwei <zhuwei@sangfor.com.cn>
Subject: Re: [PATCH v4 1/1 ] block/monitor: fix BlockJobInfoList leak in hmp_info_block_jobs()
Date: Mon, 23 Nov 2026 14:57:43 +0100	[thread overview]
Message-ID: <87a4mzveeg.fsf@pond.sub.org> (raw)
In-Reply-To: <20261123132344.3154080-2-zhuwei@sangfor.com.cn> (Zhu Wei's message of "Mon, 23 Nov 2026 21:23:42 +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: 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.


      reply	other threads:[~2026-11-23 13:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=87a4mzveeg.fsf@pond.sub.org \
    --to=armbru@pond.sub.org \
    --cc=marcandre.lureau@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.