qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Laurent Vivier <Laurent@vivier.eu>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, qemu-devel@nongnu.org
Subject: Re: [PATCH] macfb: fix a memory leak (CID 1465231)
Date: Fri, 5 Nov 2021 18:43:01 +0000	[thread overview]
Message-ID: <CAFEAcA-Yz0ww_1C22X-DmCsN7t=1URrt4p6SL2UHHMhRPomDkQ@mail.gmail.com> (raw)
In-Reply-To: <3f1bcc4e-2b53-8f54-e927-d52aef76a9c6@vivier.eu>

On Fri, 5 Nov 2021 at 18:32, Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 05/11/2021 à 18:01, Peter Maydell a écrit :
> > On Fri, 5 Nov 2021 at 16:52, Laurent Vivier <laurent@vivier.eu> wrote:
> >>
> >> Rewrite the function using g_string_append_printf() rather than
> >> g_strdup_printf()/g_strconcat().
> >>
> >> Fixes: df8abbbadf74 ("macfb: add common monitor modes supported by the MacOS toolbox ROM")
> >> Cc: mark.cave-ayland@ilande.co.uk
> >> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> >> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> >> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> >> ---
> >>   hw/display/macfb.c | 11 ++++-------
> >>   1 file changed, 4 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/hw/display/macfb.c b/hw/display/macfb.c
> >> index 4b352eb89c3f..277d3e663331 100644
> >> --- a/hw/display/macfb.c
> >> +++ b/hw/display/macfb.c
> >> @@ -440,21 +440,18 @@ static MacFbMode *macfb_find_mode(MacfbDisplayType display_type,
> >>
> >>   static gchar *macfb_mode_list(void)
> >>   {
> >> -    gchar *list = NULL;
> >> -    gchar *mode;
> >> +    GString *list = g_string_new("");
> >>       MacFbMode *macfb_mode;
> >>       int i;
> >>
> >>       for (i = 0; i < ARRAY_SIZE(macfb_mode_table); i++) {
> >>           macfb_mode = &macfb_mode_table[i];
> >>
> >> -        mode = g_strdup_printf("    %dx%dx%d\n", macfb_mode->width,
> >> +        g_string_append_printf(list, "    %dx%dx%d\n", macfb_mode->width,
> >>                                  macfb_mode->height, macfb_mode->depth);
> >> -        list = g_strconcat(mode, list, NULL);
> >> -        g_free(mode);
> >>       }
> >>
> >> -    return list;
> >> +    return g_string_free(list, FALSE);
> >
> > This reverses the order compared to the old code (which prepends
> > 'mode' to the 'list' string it is building up). Does that matter ?
> >
>
> Not at all. Perhaps it's even better like that as we have lower resolutions first.

In that case,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


  reply	other threads:[~2021-11-05 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 16:52 [PATCH] macfb: fix a memory leak (CID 1465231) Laurent Vivier
2021-11-05 17:01 ` Peter Maydell
2021-11-05 18:32   ` Laurent Vivier
2021-11-05 18:43     ` Peter Maydell [this message]
2021-11-08  8:06 ` Mark Cave-Ayland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFEAcA-Yz0ww_1C22X-DmCsN7t=1URrt4p6SL2UHHMhRPomDkQ@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=Laurent@vivier.eu \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).