From 3ef8637b68d98f2cb1d06362046592e058ee5f4a Mon Sep 17 00:00:00 2001 From: Richard Rauch Date: Mon, 3 Nov 2003 21:41:07 +0000 Subject: [PATCH] Fixed a memory leak (thanks for the correction, John!). Smoothed over some code style issues while I was here, but left the init-string parsing alone for now. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@292 7f0cb862-5218-0410-a997-914c9d46530a --- src/freeglut_init.c | 78 +++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/freeglut_init.c b/src/freeglut_init.c index dc25180..33b5998 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -37,11 +37,13 @@ /* * TODO BEFORE THE STABLE RELEASE: * - * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific deinitialization done + * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific + * deinitialization done * glutInitDisplayString() -- display mode string parsing * - * Wouldn't it be cool to use gettext() for error messages? I just love bash saying - * "nie znaleziono pliku" instead of "file not found" :) Is gettext easily portable? + * Wouldn't it be cool to use gettext() for error messages? I just love + * bash saying "nie znaleziono pliku" instead of "file not found" :) + * Is gettext easily portable? */ /* -- GLOBAL VARIABLES ----------------------------------------------------- */ @@ -216,29 +218,29 @@ void fgDeinitialize( void ) /* * If there was a menu created, destroy the rendering context */ - if ( fgStructure.MenuContext ) + if( fgStructure.MenuContext ) { - free ( fgStructure.MenuContext ) ; - fgStructure.MenuContext = NULL ; + free( fgStructure.MenuContext ); + fgStructure.MenuContext = NULL; } fgDestroyStructure(); - while ( (timer = (SFG_Timer *)fgState.Timers.First) != NULL ) + while( timer = (SFG_Timer *)fgState.Timers.First ) { - fgListRemove ( &fgState.Timers, &timer->Node ) ; - free ( timer ) ; + fgListRemove ( &fgState.Timers, &timer->Node ); + free( timer ); } - fgJoystickClose(); + fgJoystickClose( ); - fgState.Position.X = -1 ; - fgState.Position.Y = -1 ; - fgState.Position.Use = FALSE ; + fgState.Position.X = -1; + fgState.Position.Y = -1; + fgState.Position.Use = FALSE; - fgState.Size.X = 300 ; - fgState.Size.Y = 300 ; - fgState.Size.Use = TRUE ; + fgState.Size.X = 300; + fgState.Size.Y = 300; + fgState.Size.Use = TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; @@ -258,26 +260,35 @@ void fgDeinitialize( void ) fgState.GameModeDepth = 16; fgState.GameModeRefresh = 72; - fgState.Time.Set = FALSE ; + fgState.Time.Set = FALSE; - fgState.Timers.First = fgState.Timers.Last = NULL ; - fgState.IdleCallback = NULL ; - fgState.MenuStateCallback = (FGCBmenuState)NULL ; - fgState.MenuStatusCallback = (FGCBmenuStatus)NULL ; + fgState.Timers.First = fgState.Timers.Last = NULL; + fgState.IdleCallback = NULL; + fgState.MenuStateCallback = (FGCBmenuState)NULL; + fgState.MenuStatusCallback = (FGCBmenuStatus)NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; + if( fgState.ProgramName ) + { + free( fgState.ProgramName ); + fgState.ProgramName = NULL; + } + + #if TARGET_HOST_UNIX_X11 /* - * Make sure all X-client data we have created will be destroyed on display closing + * Make sure all X-client data we have created will be destroyed on + * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* - * Close the display connection, destroying all windows we have created so far + * Close the display connection, destroying all windows we have + * created so far */ XCloseDisplay( fgDisplay.Display ); @@ -317,22 +328,22 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) /* check if GLUT_FPS env var is set */ { - const char *fps = getenv ( "GLUT_FPS" ); - if ( fps ) - { - sscanf ( fps, "%d", &fgState.FPSInterval ) ; - if ( fgState.FPSInterval <= 0 ) - fgState.FPSInterval = 5000 ; /* 5000 milliseconds */ - } + const char *fps = getenv ( "GLUT_FPS" ); + if( fps ) + { + sscanf( fps, "%d", &fgState.FPSInterval ); + if( fgState.FPSInterval <= 0 ) + fgState.FPSInterval = 5000; /* 5000 milliseconds */ + } } #if TARGET_HOST_WIN32 - if ( !getenv ( "DISPLAY" ) ) - displayName = strdup ( "" ) ; + if( !getenv( "DISPLAY" ) ) + displayName = strdup( "" ); else #endif displayName = strdup( getenv( "DISPLAY" ) ); - if (!displayName) + if( !displayName ) fgError ("Could not allocate space for display name."); for( i=1; i= 0) && (y >= 0) ) { - fgState.Position.X = x; fgState.Position.Y = y; fgState.Position.Use = TRUE; -- 1.7.10.4