qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] cutils: Fix memleak in get_relocated_path()
  2021-04-26 22:30 [PATCH] cutils: Fix memleak in get_relocated_path() Zhenzhong Duan
@ 2021-04-26 14:06 ` Philippe Mathieu-Daudé
  2021-04-27  3:16   ` Duan, Zhenzhong
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-26 14:06 UTC (permalink / raw)
  To: Zhenzhong Duan, qemu-devel; +Cc: qemu-trivial, pbonzini, Stefano Garzarella

Hi,

On 4/27/21 12:30 AM, Zhenzhong Duan wrote:
> Valgrind complains definitely loss in get_relocated_path(), because
> GString is leaked in get_relocated_path() when returning with gchar *.
> Use g_string_free(, false) to free GString while preserving gchar *.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  util/cutils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/cutils.c b/util/cutils.c
> index ee908486da..f58c2157d2 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
>          assert(G_IS_DIR_SEPARATOR(dir[-1]));
>          g_string_append(result, dir - 1);
>      }
> -    return result->str;
> +    return g_string_free(result, FALSE);
>  }
> 

Thanks for your patch, but Stefano sent the same fix 2 weeks ago:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg798279.html

It should be merged once the development tree opens again (we are
now 'freezed' before the v6.0.0 release).

You might want to send your Review-by or Tested-by tag to Stefano's
patch.

Regards,

Phil.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] cutils: Fix memleak in get_relocated_path()
@ 2021-04-26 22:30 Zhenzhong Duan
  2021-04-26 14:06 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2021-04-26 22:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, pbonzini, Zhenzhong Duan

Valgrind complains definitely loss in get_relocated_path(), because
GString is leaked in get_relocated_path() when returning with gchar *.
Use g_string_free(, false) to free GString while preserving gchar *.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/cutils.c b/util/cutils.c
index ee908486da..f58c2157d2 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
         assert(G_IS_DIR_SEPARATOR(dir[-1]));
         g_string_append(result, dir - 1);
     }
-    return result->str;
+    return g_string_free(result, FALSE);
 }
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] cutils: Fix memleak in get_relocated_path()
  2021-04-26 14:06 ` Philippe Mathieu-Daudé
@ 2021-04-27  3:16   ` Duan, Zhenzhong
  0 siblings, 0 replies; 3+ messages in thread
From: Duan, Zhenzhong @ 2021-04-27  3:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-trivial, pbonzini, Stefano Garzarella


> -----Original Message-----
> From: Philippe Mathieu-Daudé <philmd@redhat.com>
> Sent: Monday, April 26, 2021 10:06 PM
> To: Duan, Zhenzhong <zhenzhong.duan@intel.com>; qemu-
> devel@nongnu.org
> Cc: qemu-trivial@nongnu.org; pbonzini@redhat.com; Stefano Garzarella
> <sgarzare@redhat.com>
> Subject: Re: [PATCH] cutils: Fix memleak in get_relocated_path()
> 
> Hi,
> 
> On 4/27/21 12:30 AM, Zhenzhong Duan wrote:
> > Valgrind complains definitely loss in get_relocated_path(), because
> > GString is leaked in get_relocated_path() when returning with gchar *.
> > Use g_string_free(, false) to free GString while preserving gchar *.
> >
> > Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> > ---
> >  util/cutils.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/util/cutils.c b/util/cutils.c index
> > ee908486da..f58c2157d2 100644
> > --- a/util/cutils.c
> > +++ b/util/cutils.c
> > @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
> >          assert(G_IS_DIR_SEPARATOR(dir[-1]));
> >          g_string_append(result, dir - 1);
> >      }
> > -    return result->str;
> > +    return g_string_free(result, FALSE);
> >  }
> >
> 
> Thanks for your patch, but Stefano sent the same fix 2 weeks ago:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg798279.html
> 
> It should be merged once the development tree opens again (we are now
> 'freezed' before the v6.0.0 release).

I see, thanks for your quick response.

Zhenzhong

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-27  3:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 22:30 [PATCH] cutils: Fix memleak in get_relocated_path() Zhenzhong Duan
2021-04-26 14:06 ` Philippe Mathieu-Daudé
2021-04-27  3:16   ` Duan, Zhenzhong

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).