OpenGL Memory leakage-initialization Function ()

Source: Internet
Author: User

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!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.