cutils: Fix memleak in get_relocated_path()
PATCH 1/1 cutils: Fix memleak in get_relocated_path()
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 *.
--- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/cutils.c +1 -1
@@ -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); }
Signature · 1 line
2.25.1
Hi,
Quoted 15 lines · Zhenzhong Duan
Valgrind complains definitely loss in
get_relocated_path(), because GString is leaked inget_relocated_path()when returning with gchar *. Useg_string_free(, false)to free GString while preserving gchar *.Signed-off-by Zhenzhong Duan <[email protected]>--- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/cutils.c +0
-0
util/cutils.c char *get_relocated_path(const char *dir) · line 1059
Quoted 6 lines
util/cutils.c +1
-1@@ -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/[email protected]/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.
Quoted 38 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Monday, April 26, 2021 10:06 PM
To: Duan, Zhenzhong <[email protected]>; qemu- [email protected]
Cc: [email protected]; [email protected]; Stefano Garzarella <[email protected]>
Subject: Re: [PATCH] cutils: Fix memleak inget_relocated_path()Hi,
Quoted 15 lines · Zhenzhong Duan
Valgrind complains definitely loss in
get_relocated_path(), because GString is leaked inget_relocated_path()when returning with gchar *. Useg_string_free(, false)to free GString while preserving gchar *.Signed-off-by Zhenzhong Duan <[email protected]>--- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/cutils.c index renamed from util/cutils.c +0
-0
ee908486da..f58c2157d2100644util/cutils.c char *get_relocated_path(const char *dir) · line 1059
Quoted 6 lines
util/cutils.c +1
-1@@ -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/[email protected]/msg798279.html
Quoted 2 lines
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