Skip to contentSkip to conversation

ui/cocoa: Fix the leak of qemu_console_get_label

PATCH In review Akihiko Odaki 3 participants 3 messages Feb 13, 2022 – Feb 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/cocoa: Fix the leak of qemu_console_get_label

---
 ui/cocoa.m | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
ui/cocoa.m +4 -1
index ac18e14ce01..fdf52a7c2f7 100644
@@ -1680,7 +1680,10 @@ static void create_initial_menus(void)
 /* Returns a name for a given console */
 static NSString * getConsoleName(QemuConsole * console)
 {
-    return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)];
+    char *label = qemu_console_get_label(console);
+    NSString *nslabel = [NSString stringWithUTF8String:label];
+    g_free(label);
+    return nslabel;
 }
 
 /* Add an entry to the View menu for each console */
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw
Quoted 10 lines · Akihiko Odaki

---
ui/cocoa.m | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
ui/cocoa.m +0 -0
index ac18e14ce01..fdf52a7c2f7 100644

ui/cocoa.m static void create_initial_menus(void) · line 1683

Quoted 5 lines
ui/cocoa.m +1 -1
@@ -1680,7 +1680,10 @@ static void create_initial_menus(void)
 /* Returns a name for a given console */
 static NSString * getConsoleName(QemuConsole * console)
 {
-    return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)];
+    char *label = qemu_console_get_label(console);

I guess you could do g_autofree char *label to save a g_free but not a big deal and only saves one line here so it's also good as it is.

Regards,
BALATON Zoltan

Quoted 7 lines
ui/cocoa.m +3 -0
+    NSString *nslabel = [NSString stringWithUTF8String:label];
+    g_free(label);
+    return nslabel;
 }
 
 /* Add an entry to the View menu for each console */
Reviewed-by Philippe Mathieu-Daudé
#2 lore raw
Quoted 6 lines · BALATON Zoltan
Quoted 5 lines · Akihiko Odaki

---
ui/cocoa.m | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 13 lines

ui/cocoa.m static void create_initial_menus(void) · line 1684

Quoted 11 lines
ui/cocoa.m +1 -1
index ac18e14ce01..fdf52a7c2f7 100644
@@ -1680,7 +1680,10 @@ static void create_initial_menus(void)
 /* Returns a name for a given console */
 static NSString * getConsoleName(QemuConsole * console)
 {
-    return [NSString stringWithFormat: @"%s", 
 qemu_console_get_label(console)];
+    char *label = qemu_console_get_label(console);

I guess you could do g_autofree char *label to save a g_free but not a big deal and only saves one line here so it's also good as it is.

Good idea.