qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Pan Nengyuan <pannengyuan@huawei.com>, kwolf@redhat.com
Cc: euler.robot@huawei.com, qemu-devel@nongnu.org,
	qemu-block@nongnu.org, zhang.zhanghailiang@huawei.com
Subject: Re: [PATCH 2/2] qemu-img: free memory before re-assign
Date: Wed, 26 Feb 2020 11:13:48 +0100	[thread overview]
Message-ID: <03a50206-6407-41e8-f11a-6e866f0c3798@redhat.com> (raw)
In-Reply-To: <20200226033037.18253-3-pannengyuan@huawei.com>


[-- Attachment #1.1: Type: text/plain, Size: 813 bytes --]

On 26.02.20 04:30, Pan Nengyuan wrote:
> collect_image_check() is called twice in img_check(), the filename/format will be alloced without free the original memory.
> It is not a big deal since the process will exit anyway, but seems like a clean code and it will remove the warning spotted by asan.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> ---
>  qemu-img.c | 2 ++
>  1 file changed, 2 insertions(+)

I think this should happen in the caller.  And there I think it would
make more sense to completely discard the old object and allocate a new one:

qapi_free_ImageCheck(check);
check = g_new0(ImageCheck, 1);

This way, we can’t forget to free any fields if new pointers were to be
added to the ImageCheck object.

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-02-26 10:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  3:30 [PATCH 0/2] fix two small memleaks Pan Nengyuan
2020-02-26  3:30 ` [PATCH 1/2] block/qcow2: do free crypto_opts in qcow2_close() Pan Nengyuan
2020-02-26 10:14   ` Max Reitz
2020-02-26  3:30 ` [PATCH 2/2] qemu-img: free memory before re-assign Pan Nengyuan
2020-02-26 10:13   ` Max Reitz [this message]
2020-02-26 10:32     ` Pan Nengyuan

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=03a50206-6407-41e8-f11a-6e866f0c3798@redhat.com \
    --to=mreitz@redhat.com \
    --cc=euler.robot@huawei.com \
    --cc=kwolf@redhat.com \
    --cc=pannengyuan@huawei.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).