Message ID | 20220213021329.2066-1-akihiko.odaki@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ui/cocoa: Fix the leak of qemu_console_get_label | expand |
On Sun, 13 Feb 2022, Akihiko Odaki wrote: > Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> > --- > ui/cocoa.m | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/ui/cocoa.m b/ui/cocoa.m > index ac18e14ce01..fdf52a7c2f7 100644 > --- a/ui/cocoa.m > +++ b/ui/cocoa.m > @@ -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 > + NSString *nslabel = [NSString stringWithUTF8String:label]; > + g_free(label); > + return nslabel; > } > > /* Add an entry to the View menu for each console */ >
On 13/2/22 12:11, BALATON Zoltan wrote: > On Sun, 13 Feb 2022, Akihiko Odaki wrote: >> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> >> --- >> ui/cocoa.m | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/ui/cocoa.m b/ui/cocoa.m >> index ac18e14ce01..fdf52a7c2f7 100644 >> --- a/ui/cocoa.m >> +++ b/ui/cocoa.m >> @@ -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. Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
diff --git a/ui/cocoa.m b/ui/cocoa.m index ac18e14ce01..fdf52a7c2f7 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -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 */
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> --- ui/cocoa.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)