From dd88123ad16ce27690a2aac94127175ed5213c64 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 28 Sep 2022 00:47:53 +0200 Subject: Dont use free'd fbconfigs --- include/mgl/mgl.h | 1 + src/mgl.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/mgl/mgl.h b/include/mgl/mgl.h index bd0ae5b..b43e4b9 100644 --- a/include/mgl/mgl.h +++ b/include/mgl/mgl.h @@ -10,6 +10,7 @@ typedef struct mgl_context mgl_context; struct mgl_context { mgl_connection connection; mgl_gl gl; + GLXFBConfig *fbconfigs; _XVisualInfo *visual_info; GLXFBConfig fbconfig; unsigned long wm_delete_window_atom; diff --git a/src/mgl.c b/src/mgl.c index 3bf8821..8988003 100644 --- a/src/mgl.c +++ b/src/mgl.c @@ -36,13 +36,14 @@ static int glx_context_init() { None }; + context.fbconfigs = NULL; context.visual_info = NULL; context.fbconfig = NULL; int numfbconfigs = 0; - GLXFBConfig *fbconfigs = context.gl.glXChooseFBConfig(context.connection, DefaultScreen(context.connection), attr, &numfbconfigs); + context.fbconfigs = context.gl.glXChooseFBConfig(context.connection, DefaultScreen(context.connection), attr, &numfbconfigs); for(int i = 0; i < numfbconfigs; i++) { - context.visual_info = context.gl.glXGetVisualFromFBConfig(context.connection, fbconfigs[i]); + context.visual_info = context.gl.glXGetVisualFromFBConfig(context.connection, context.fbconfigs[i]); if(!context.visual_info) continue; @@ -53,7 +54,7 @@ static int glx_context_init() { continue; } - context.fbconfig = fbconfigs[i]; + context.fbconfig = context.fbconfigs[i]; if(pict_format->direct.alphaMask > 0) break; @@ -62,9 +63,6 @@ static int glx_context_init() { context.fbconfig = NULL; } - if(fbconfigs) - XFree(fbconfigs); - if(!context.visual_info) { fprintf(stderr, "mgl error: no appropriate visual found\n"); return -1; @@ -78,6 +76,11 @@ static void glx_context_deinit() { XFree(context.visual_info); context.visual_info = NULL; } + + if(context.fbconfigs) { + XFree(context.fbconfigs); + context.fbconfigs = NULL; + } } int mgl_init(void) { -- cgit v1.2.3