Fixed part of bug #926883 (Video mode matching code, memory leaks,
authorSven Panne <sven.panne@aedion.de>
Mon, 3 Jan 2005 14:14:56 +0000 (14:14 +0000)
committerSven Panne <sven.panne@aedion.de>
Mon, 3 Jan 2005 14:14:56 +0000 (14:14 +0000)
fullscreen), i.e. memory leak caused by not freeing the mode lines
returned by XF86VidModeGetAllModeLines

git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@557 7f0cb862-5218-0410-a997-914c9d46530a

ChangeLog
src/freeglut_gamemode.c

index 732fb76..c385ac4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -891,3 +891,7 @@ default.
 
 (232) Improved error message a bit when no suitable visual could be found
 (X11 only).
+
+(233) Fixed part of bug #926883 (Video mode matching code, memory leaks,
+fullscreen), i.e. memory leak caused by not freeing the mode lines returned
+by XF86VidModeGetAllModeLines
index f57d935..404b6c1 100644 (file)
@@ -180,9 +180,10 @@ static void fghRestoreState( void )
                  */
                 XFlush( fgDisplay.Display );
 
-                return;
+                break;
             }
         }
+        XFree( displayModes );
     }
 
 #   else
@@ -217,6 +218,7 @@ static GLboolean fghCheckDisplayMode( int width, int height, int depth, int refr
  */
 static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
 {
+    GLboolean success = GL_FALSE;
 #if TARGET_HOST_UNIX_X11
 
     /*
@@ -249,22 +251,21 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
                                      fgState.GameModeDepth,
                                      fgState.GameModeRefresh ) )
             {
-                if( haveToTest )
-                    return GL_TRUE;
                 /* OKi, this is the display mode we have been looking for... */
-                XF86VidModeSwitchToMode(
-                    fgDisplay.Display,
-                    fgDisplay.Screen,
-                    displayModes[ i ]
-                );
-                return GL_TRUE;
+                if( !haveToTest ) {
+                    XF86VidModeSwitchToMode(
+                        fgDisplay.Display,
+                        fgDisplay.Screen,
+                        displayModes[ i ]
+                    );
+                }
+                success = GL_TRUE;
+                break;
             }
         }
+        XFree( displayModes );
     }
 
-    /* Something must have gone wrong */
-    return GL_FALSE;
-
 #   else
     /*
      * XXX warning fghChangeDisplayMode: missing XFree86 video mode extensions,
@@ -275,7 +276,6 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
 
     unsigned int    displayModes = 0, mode = 0xffffffff;
-    GLboolean success = GL_FALSE;
     /* HDC      desktopDC; */
     DEVMODE  devMode;
 
@@ -341,9 +341,9 @@ static GLboolean fghChangeDisplayMode( GLboolean haveToTest )
         }
     }
 
-    return success;
-
 #endif
+
+    return success;
 }