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.