qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PULL 09/13] macfb: add common monitor modes supported by the MacOS


From: Laurent Vivier
Subject: Re: [PULL 09/13] macfb: add common monitor modes supported by the MacOS toolbox ROM
Date: Fri, 5 Nov 2021 17:43:42 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

Le 05/11/2021 à 16:56, Peter Maydell a écrit :
On Fri, 8 Oct 2021 at 12:57, Laurent Vivier <laurent@vivier.eu> wrote:

From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

The monitor modes table is found by experimenting with the Monitors Control
Panel in MacOS and analysing the reads/writes. From this it can be found that
the mode is controlled by writes to the DAFB_MODE_CTRL1 and DAFB_MODE_CTRL2
registers.

Hi; Coverity points out a memory leak here (CID 1465231):

+static gchar *macfb_mode_list(void)
+{
+    gchar *list = NULL;
+    gchar *mode;
+    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,
+                               macfb_mode->height, macfb_mode->depth);
+        list = g_strconcat(mode, list, NULL);
+        g_free(mode);

We pass the old value of 'list' to g_strconcat(), which allocates
new memory and returns it; the 'list = ' overwrites the old 'list'
value. So the old string is leaked, because g_strconcat() won't
free it for you.

Coverity also complains that we pass NULL as argument 2 to
g_strconcat() the first time through the loop and this is bad;
I'm not sure whether it's wrong or not.

This function might be better written to use GString and
g_string_append_printf() to add each line to the GString.


I'm going to send a fix according to your comments.

Thanks,
Laurent




reply via email to

[Prev in Thread] Current Thread [Next in Thread]