winex11.drv: Replace an strdup() with HeapAlloc() in the OpenGL code.

Francois Gouget fgouget at free.fr
Mon May 25 17:52:05 CDT 2009


Free the corresponding memory when the library is unloaded.
---

Seeing that this buffer was never freed I added code to free it when the 
dll gets unloaded.

Also, the reason we don't get this type of issue with the other strings 
(i.e. we don't have to strdup() them, is because they are (essentially) 
not used after we get out of X11DRV_WineGL_InitOpenglInfo()).

 dlls/winex11.drv/opengl.c      |   18 +++++++++++++++---
 dlls/winex11.drv/x11drv.h      |    1 +
 dlls/winex11.drv/x11drv_main.c |    1 +
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c
index b15b4e2..e835f9a 100644
--- a/dlls/winex11.drv/opengl.c
+++ b/dlls/winex11.drv/opengl.c
@@ -76,7 +76,7 @@ typedef struct wine_glextension {
 
 struct WineGLInfo {
     const char *glVersion;
-    const char *glExtensions;
+    char *glExtensions;
 
     int glxVersion[2];
 
@@ -274,12 +274,13 @@ MAKE_FUNCPTR(glFinish)
 MAKE_FUNCPTR(glFlush)
 #undef MAKE_FUNCPTR
 
+static BOOL infoInitialized = FALSE;
 static BOOL X11DRV_WineGL_InitOpenglInfo(void)
 {
-    static BOOL infoInitialized = FALSE;
 
     int screen = DefaultScreen(gdi_display);
     Window win = RootWindow(gdi_display, screen);
+    const char* str;
     Visual *visual;
     XVisualInfo template;
     XVisualInfo *vis;
@@ -318,7 +319,9 @@ static BOOL X11DRV_WineGL_InitOpenglInfo(void)
     }
 
     WineGLInfo.glVersion = (const char *) pglGetString(GL_VERSION);
-    WineGLInfo.glExtensions = strdup((const char *) pglGetString(GL_EXTENSIONS));
+    str = (const char *) pglGetString(GL_EXTENSIONS);
+    WineGLInfo.glExtensions = HeapAlloc(GetProcessHeap(), 0, strlen(str)+1);
+    strcpy(WineGLInfo.glExtensions, str);
 
     /* Get the common GLX version supported by GLX client and server ( major/minor) */
     pglXQueryVersion(gdi_display, &WineGLInfo.glxVersion[0], &WineGLInfo.glxVersion[1]);
@@ -352,6 +355,15 @@ static BOOL X11DRV_WineGL_InitOpenglInfo(void)
     return TRUE;
 }
 
+void X11DRV_OpenGL_Cleanup(void)
+{
+    if (infoInitialized)
+    {
+        HeapFree(GetProcessHeap(), 0, WineGLInfo.glExtensions);
+        infoInitialized = FALSE;
+    }
+}
+
 static BOOL has_opengl(void)
 {
     static int init_done;
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index a40dd10..d840cb8 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -232,6 +232,7 @@ extern int CDECL X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
 					PIXELFORMATDESCRIPTOR *ppfd);
 extern int CDECL X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev);
 extern BOOL CDECL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev);
+extern void X11DRV_OpenGL_Cleanup(void);
 
 /* X11 driver internal functions */
 
diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c
index 020d6b5..41c866c 100644
--- a/dlls/winex11.drv/x11drv_main.c
+++ b/dlls/winex11.drv/x11drv_main.c
@@ -587,6 +587,7 @@ static void process_detach(void)
 
     /* cleanup GDI */
     X11DRV_GDI_Finalize();
+    X11DRV_OpenGL_Cleanup();
 
     IME_UnregisterClasses();
     DeleteCriticalSection( &X11DRV_CritSection );
-- 
1.6.2.4




More information about the wine-patches mailing list