[Qemu-devel] [PATCH] vhost: fix a memory leak

Peng Hao posted 1 patch 6 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1499207612-3560-1-git-send-email-peng.hao2@zte.com.cn
Test FreeBSD passed
Test checkpatch passed
Test docker passed
Test s390x passed
hw/virtio/vhost-backend.c | 2 ++
1 file changed, 2 insertions(+)
[Qemu-devel] [PATCH] vhost: fix a memory leak
Posted by Peng Hao 6 years, 9 months ago
vhost exists a call for g_file_get_contents, but not call g_free.

Signed-off-by: Peng Hao<peng.hao2@zte.com.cn>
---
 hw/virtio/vhost-backend.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 4e31de1..2c481d6 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
         if (!((val == G_MAXUINT64 || !val) && errno)) {
+            g_free(s);
             return val;
         }
         error_report("ignoring invalid max_mem_regions value in vhost module:"
                      " %s", s);
     }
+    g_free(s);
     return limit;
 }
 
-- 
1.8.3.1



Re: [Qemu-devel] [PATCH] vhost: fix a memory leak
Posted by Marc-André Lureau 6 years, 9 months ago
Hi

On Tue, Jul 4, 2017 at 4:16 PM Peng Hao <peng.hao2@zte.com.cn> wrote:

> vhost exists a call for g_file_get_contents, but not call g_free.
>
> Signed-off-by: Peng Hao<peng.hao2@zte.com.cn>
>

 Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  hw/virtio/vhost-backend.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 4e31de1..2c481d6 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct
> vhost_dev *dev)
>                              &s, NULL, NULL)) {
>          uint64_t val = g_ascii_strtoull(s, NULL, 10);
>          if (!((val == G_MAXUINT64 || !val) && errno)) {
> +            g_free(s);
>              return val;
>          }
>          error_report("ignoring invalid max_mem_regions value in vhost
> module:"
>                       " %s", s);
>      }
> +    g_free(s);
>      return limit;
>  }
>
> --
> 1.8.3.1
>
>
>
> --
Marc-André Lureau
Re: [Qemu-devel] [PATCH] vhost: fix a memory leak
Posted by Michael S. Tsirkin 6 years, 9 months ago
On Tue, Jul 04, 2017 at 02:21:08PM +0000, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Jul 4, 2017 at 4:16 PM Peng Hao <peng.hao2@zte.com.cn> wrote:
> 
>     vhost exists a call for g_file_get_contents, but not call g_free.
> 
>     Signed-off-by: Peng Hao<peng.hao2@zte.com.cn>
> 
> 
>  Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> 
>     ---
>      hw/virtio/vhost-backend.c | 2 ++
>      1 file changed, 2 insertions(+)
> 
>     diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
>     index 4e31de1..2c481d6 100644
>     --- a/hw/virtio/vhost-backend.c
>     +++ b/hw/virtio/vhost-backend.c
>     @@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev
>     *dev)
>                                  &s, NULL, NULL)) {
>              uint64_t val = g_ascii_strtoull(s, NULL, 10);
>              if (!((val == G_MAXUINT64 || !val) && errno)) {
>     +            g_free(s);
>                  return val;
>              }
>              error_report("ignoring invalid max_mem_regions value in vhost
>     module:"
>                           " %s", s);
>          }
>     +    g_free(s);
>          return limit;
>      }
> 
>     --
>     1.8.3.1
> 

Thanks for the review.
I'd like to include your tag in commit log.
For that, could you please repost your ack in text format using
some other mail client?
My scripts don't handle the way your mail client scrambles text.

> 
> 
> --
> Marc-André Lureau

Re: [Qemu-devel] [PATCH] vhost: fix a memory leak
Posted by Marc-André Lureau 6 years, 9 months ago
Hi

On Wed, Jul 5, 2017 at 12:33 AM, Peng Hao <peng.hao2@zte.com.cn> wrote:
> vhost exists a call for g_file_get_contents, but not call g_free.
>
> Signed-off-by: Peng Hao<peng.hao2@zte.com.cn>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

mst: is this better?

> ---
>  hw/virtio/vhost-backend.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 4e31de1..2c481d6 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
>                              &s, NULL, NULL)) {
>          uint64_t val = g_ascii_strtoull(s, NULL, 10);
>          if (!((val == G_MAXUINT64 || !val) && errno)) {
> +            g_free(s);
>              return val;
>          }
>          error_report("ignoring invalid max_mem_regions value in vhost module:"
>                       " %s", s);
>      }
> +    g_free(s);
>      return limit;
>  }
>
> --
> 1.8.3.1
>
>
>



-- 
Marc-André Lureau

Re: [Qemu-devel] [PATCH] vhost: fix a memory leak
Posted by Michael S. Tsirkin 6 years, 9 months ago
On Tue, Jul 04, 2017 at 11:59:54PM +0200, Marc-André Lureau wrote:
> Hi
> 
> On Wed, Jul 5, 2017 at 12:33 AM, Peng Hao <peng.hao2@zte.com.cn> wrote:
> > vhost exists a call for g_file_get_contents, but not call g_free.
> >
> > Signed-off-by: Peng Hao<peng.hao2@zte.com.cn>
> 
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> mst: is this better?

That's fine, thanks!

> > ---
> >  hw/virtio/vhost-backend.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> > index 4e31de1..2c481d6 100644
> > --- a/hw/virtio/vhost-backend.c
> > +++ b/hw/virtio/vhost-backend.c
> > @@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
> >                              &s, NULL, NULL)) {
> >          uint64_t val = g_ascii_strtoull(s, NULL, 10);
> >          if (!((val == G_MAXUINT64 || !val) && errno)) {
> > +            g_free(s);
> >              return val;
> >          }
> >          error_report("ignoring invalid max_mem_regions value in vhost module:"
> >                       " %s", s);
> >      }
> > +    g_free(s);
> >      return limit;
> >  }
> >
> > --
> > 1.8.3.1
> >
> >
> >
> 
> 
> 
> -- 
> Marc-André Lureau