Recently, some opeggl development, using the freeglut-2.6.0 library, found that in the dialog box environment of MFC, as long as the use of the function of gluinit (& __argc, _ argv), there is a memory leakage, trackingCodeAnd the memory is allocated in the following position in the gluinit function:
Void fgapientry gluinit (int * pargc, char ** argv)
{
......
If (fgstate. initialised)
Fgerror ("illegal gluinit () reinitialization attempt ");
If (pargc & * pargc & argv & * argv & ** argv)
{
Fgstate. programname = strdup (* argv );
If (! Fgstate. programname)
Fgerror ("cocould not allocate space for the program's name .");
}
Fgcreatestructure ();
......
}
The strdup () function allocates memory with malloc () and must be released with free (). Therefore, find the places where fgstate. programname is released and find that the resources are recycled in the following functions:
Void fgdeinitialize (void)
{
......
If (fgstate. programname)
{
Free (fgstate. programname );
Fgstate. programname = NULL;
}
......
}
SoWhere is fgdeinitialize called? Found here:
/*
* Undoes all the "gluinit" stuff
*/
Void fgapientry glutexit (void)
{
Fgdeinitialize ();
}
If you look at the comments on this function, everything is explained.ProgramCall glutexit () before exiting. The memory leakage is repaired!