public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: zhaoguohan@kylinos.cn
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v2] block/curl: factor common cleanup and free password
Date: Tue, 24 Mar 2026 09:19:59 +0000	[thread overview]
Message-ID: <acJXP9cmJP9h7oYi@redhat.com> (raw)
In-Reply-To: <20260324061345.975935-1-zhaoguohan@kylinos.cn>

On Tue, Mar 24, 2026 at 02:13:45PM +0800, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> Factor duplicated cleanup code into a helper and reuse it in the
> open failure path and curl_close().
> 
> Also free s->password, fixing a leak.

Please don't mix bug fixes with refactorings. These should be
separate commits.

> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
>  block/curl.c | 38 +++++++++++++++++++++++---------------
>  1 file changed, 23 insertions(+), 15 deletions(-)
> 
> diff --git a/block/curl.c b/block/curl.c
> index 66aecfb20ec6..577b8d5a4e67 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -622,6 +622,27 @@ static void curl_attach_aio_context(BlockDriverState *bs,
>      curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_timer_cb);
>  }
>  
> +static void curl_cleanup(BDRVCURLState *s)
> +{
> +    g_free(s->cookie);
> +    s->cookie = NULL;

Use this pattern:

  g_clear_pointer(&s->cookie, g_free);

> +    g_free(s->url);
> +    s->url = NULL;
> +    g_free(s->username);
> +    s->username = NULL;
> +    g_free(s->password);
> +    s->password = NULL;
> +    g_free(s->proxyusername);
> +    s->proxyusername = NULL;
> +    g_free(s->proxypassword);
> +    s->proxypassword = NULL;
> +    if (s->sockets) {
> +        curl_drop_all_sockets(s->sockets);
> +        g_hash_table_destroy(s->sockets);
> +        s->sockets = NULL;

  g_clear_pointer(&s->sockets, g_hash_table_destroy)

> +    }
> +}
> +
>  static QemuOptsList runtime_opts = {
>      .name = "curl",
>      .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
> @@ -900,15 +921,7 @@ out:
>      state->curl = NULL;
>  out_noclean:
>      qemu_mutex_destroy(&s->mutex);
> -    g_free(s->cookie);
> -    g_free(s->url);
> -    g_free(s->username);
> -    g_free(s->proxyusername);
> -    g_free(s->proxypassword);
> -    if (s->sockets) {
> -        curl_drop_all_sockets(s->sockets);
> -        g_hash_table_destroy(s->sockets);
> -    }
> +    curl_cleanup(s);
>      qemu_opts_del(opts);
>      return -EINVAL;
>  }
> @@ -1010,12 +1023,7 @@ static void curl_close(BlockDriverState *bs)
>      curl_detach_aio_context(bs);
>      qemu_mutex_destroy(&s->mutex);
>  
> -    g_hash_table_destroy(s->sockets);
> -    g_free(s->cookie);
> -    g_free(s->url);
> -    g_free(s->username);
> -    g_free(s->proxyusername);
> -    g_free(s->proxypassword);
> +    curl_cleanup(s);
>  }
>  
>  static int64_t coroutine_fn curl_co_getlength(BlockDriverState *bs)
> -- 
> 2.43.0
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



      reply	other threads:[~2026-03-24  9:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24  3:25 回复: Re: [PATCH] block/curl: free s->password in cleanup paths 赵国汗
2026-03-24  4:53 ` Philippe Mathieu-Daudé
2026-03-24  6:10   ` [PATCH] block/curl: factor common cleanup and free password zhaoguohan
2026-03-24  6:13   ` [PATCH v2] " zhaoguohan
2026-03-24  9:19     ` Daniel P. Berrangé [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=acJXP9cmJP9h7oYi@redhat.com \
    --to=berrange@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhaoguohan@kylinos.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox