qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: "Cédric Le Goater" <clg@redhat.com>, qemu-devel@nongnu.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Eric Auger <eric.auger@redhat.com>,
	Zhenzhong Duan <zhenzhong.duan@intel.com>
Subject: Re: [PATCH] vfio/iommufd: Fix memory leak
Date: Thu, 14 Mar 2024 11:25:50 +0800	[thread overview]
Message-ID: <a947bfd9-4670-476e-b90b-cac03632ad3b@intel.com> (raw)
In-Reply-To: <20240313210628.786224-1-clg@redhat.com>

On 2024/3/14 05:06, Cédric Le Goater wrote:
> Make sure variable contents is freed if scanf fails.
> 
> Cc: Eric Auger <eric.auger@redhat.com>
> Cc: Yi Liu <yi.l.liu@intel.com>
> Cc: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Fixes: CID 1540007
> Fixes: 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend")
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/vfio/iommufd.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index a75a785e90c64cdcc4d10c88d217801b3f536cdb..cd549e0ee8573e75772c51cc96153762a6bc8550 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -152,9 +152,8 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
>   
>       if (sscanf(contents, "%d:%d", &major, &minor) != 2) {
>           error_setg(errp, "failed to get major:minor for \"%s\"", vfio_dev_path);
> -        goto out_free_dev_path;
> +        goto out_free_contents;
>       }
> -    g_free(contents);
>       vfio_devt = makedev(major, minor);
>   
>       vfio_path = g_strdup_printf("/dev/vfio/devices/%s", dent->d_name);
> @@ -166,6 +165,8 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
>       trace_iommufd_cdev_getfd(vfio_path, ret);
>       g_free(vfio_path);
>   
> +out_free_contents:
> +    g_free(contents);
>   out_free_dev_path:
>       g_free(vfio_dev_path);
>   out_close_dir:

good catch.

Reviewed-by: Yi Liu <yi.l.liu@intel.com>

-- 
Regards,
Yi Liu


  parent reply	other threads:[~2024-03-14  3:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 21:06 [PATCH] vfio/iommufd: Fix memory leak Cédric Le Goater
2024-03-13 21:11 ` Eric Auger
2024-03-14  3:25 ` Yi Liu [this message]
2024-03-14  3:31 ` Duan, Zhenzhong
2024-03-14  8:22   ` Cédric Le Goater

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=a947bfd9-4670-476e-b90b-cac03632ad3b@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.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).