Skip to contentSkip to conversation

cutils: Fix memleak in get_relocated_path()

PATCH In review Zhenzhong Duan 2 participants 3 messages Apr 26, 2021 – Apr 27, 2021

lore
Share & tools
lore
#0 lore raw

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
index ee908486da..f58c2157d2 100644
@@ -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
#1 lore raw

Hi,

Quoted 15 lines · 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 *.

---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/cutils.c +0 -0
index ee908486da..f58c2157d2 100644

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.

#2 lore raw
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 in get_relocated_path()

Hi,

Quoted 15 lines · 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 *.

---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/cutils.c index renamed from util/cutils.c +0 -0

ee908486da..f58c2157d2 100644

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

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