summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2018-04-03 16:54:00 +0100
committerAdam Jackson <ajax@redhat.com>2018-04-09 17:07:05 -0400
commitb9764b8489cabd15b50c360cfbd799fdab0883fd (patch)
treeb8e328dd8d8008acdb6d99dcaa8add81b85d9ff6
parente0a137ce5d653063604fa8d16c8498b8ac3ab3a7 (diff)
hw/xwin/glx: Allocate fbconfigs correctly
4b0a3cba fixed leaking of GLX fbconfigs, so now xwin needs to allocate them correctly (individually, rather than all at once), so they can be freed successfully. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk> Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
-rw-r--r--hw/xwin/glx/indirect.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index fb46e1c6a..1aaa87d8f 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -1744,7 +1744,7 @@ fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig * mode,
static void
glxWinCreateConfigs(HDC hdc, glxWinScreen * screen)
{
- GLXWinConfig *c, *result, *prev = NULL;
+ GLXWinConfig *first = NULL, *prev = NULL;
int numConfigs = 0;
int i = 0;
int n = 0;
@@ -1761,22 +1761,16 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen * screen)
LogMessage(X_INFO, "%d pixel formats reported by DescribePixelFormat\n",
numConfigs);
- /* alloc */
- result = malloc(sizeof(GLXWinConfig) * numConfigs);
-
- if (NULL == result) {
- return;
- }
-
- memset(result, 0, sizeof(GLXWinConfig) * numConfigs);
n = 0;
/* fill in configs */
for (i = 0; i < numConfigs; i++) {
int rc;
+ GLXWinConfig temp;
+ GLXWinConfig *c = &temp;
+ GLXWinConfig *work;
+ memset(c, 0, sizeof(GLXWinConfig));
- c = &(result[i]);
- c->base.next = NULL;
c->pixelFormatIndex = i + 1;
rc = DescribePixelFormat(hdc, i + 1, sizeof(PIXELFORMATDESCRIPTOR),
@@ -1939,18 +1933,29 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen * screen)
n++;
+ // allocate and save
+ work = malloc(sizeof(GLXWinConfig));
+ if (NULL == work) {
+ ErrorF("Failed to allocate GLXWinConfig\n");
+ break;
+ }
+ *work = temp;
+
+ // note the first config
+ if (!first)
+ first = work;
+
// update previous config to point to this config
if (prev)
- prev->base.next = &(c->base);
-
- prev = c;
+ prev->base.next = &(work->base);
+ prev = work;
}
GLWIN_DEBUG_MSG
("found %d pixelFormats suitable for conversion to fbConfigs", n);
screen->base.numFBConfigs = n;
- screen->base.fbconfigs = &(result->base);
+ screen->base.fbconfigs = first ? &(first->base) : NULL;
}
// helper function to access an attribute value from an attribute value array by attribute
@@ -1980,7 +1985,7 @@ getAttrValue(const int attrs[], int values[], unsigned int num, int attr,
static void
glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
{
- GLXWinConfig *c, *result, *prev = NULL;
+ GLXWinConfig *first = NULL, *prev = NULL;
int i = 0;
int n = 0;
@@ -2006,14 +2011,6 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
"%d pixel formats reported by wglGetPixelFormatAttribivARB\n",
numConfigs);
- /* alloc */
- result = malloc(sizeof(GLXWinConfig) * numConfigs);
-
- if (NULL == result) {
- return;
- }
-
- memset(result, 0, sizeof(GLXWinConfig) * numConfigs);
n = 0;
#define ADD_ATTR(a) { attrs[num_attrs++] = a; assert(num_attrs < ARRAY_SIZE(attrs)); }
@@ -2074,9 +2071,11 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
/* fill in configs */
for (i = 0; i < numConfigs; i++) {
int values[num_attrs];
+ GLXWinConfig temp;
+ GLXWinConfig *c = &temp;
+ GLXWinConfig *work;
+ memset(c, 0, sizeof(GLXWinConfig));
- c = &(result[i]);
- c->base.next = NULL;
c->pixelFormatIndex = i + 1;
if (!wglGetPixelFormatAttribivARBWrapper
@@ -2329,13 +2328,24 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
n++;
+ // allocate and save
+ work = malloc(sizeof(GLXWinConfig));
+ if (NULL == work) {
+ ErrorF("Failed to allocate GLXWinConfig\n");
+ break;
+ }
+ *work = temp;
+
+ // note the first config
+ if (!first)
+ first = work;
+
// update previous config to point to this config
if (prev)
- prev->base.next = &(c->base);
-
- prev = c;
+ prev->base.next = &(work->base);
+ prev = work;
}
screen->base.numFBConfigs = n;
- screen->base.fbconfigs = &(result->base);
+ screen->base.fbconfigs = first ? &(first->base) : NULL;
}