Advertisement

Lesson 22, Memory Leak??

Started by July 23, 2003 02:03 PM
1 comment, last by Briskon 21 years, 7 months ago
I noticed in lesson 22, in the LoadGLTextures() function, when the author is creating the textures for the logos, he doesn''t free up the memory for the image used for the alpha value of the texture...........so is there a memory leak occurring here or am I missing something?

if (Image=auxDIBImageLoad("Data/OpenGL_ALPHA.bmp")) {
		alpha=new char[4*Image->sizeX*Image->sizeY];
		// Create Memory For RGBA8-Texture

		for (int a=0; a<Image->sizeX*Image->sizeY; a++)
			alpha[4*a+3]=Image->data[a*3];				
// The image has been assigned to a new bitmap without freeing 

// up the first one??? Memory  Leak???????

if (!(Image=auxDIBImageLoad("Data/OpenGL.bmp"))) status=false;
   for (a=0; a<Image->sizeX*Image->sizeY; a++) {
		alpha[4*a]=Image->data[a*3];					alpha[4*a+1]=Image->data[a*3+1];				alpha[4*a+2]=Image->data[a*3+2];				}
		//............

		//Create textures..

		//............		

		if (Image) {							  if (Image->data)
                    delete Image->data;					        delete Image;

		Image=NULL;
           	}		
}

Also in the initMultitexture() function he uses the strdup function to duplicate a string , yet, here again he doesn''t free up the memory allocated by this function. Am I wrong about these issues? Or are these real errors? I''ve only been using OpenGL for the last week so I''m not sure if I''m reading this right?
Just noticed something else........
Is it right to use "delete Image" to delete the image data?

All the other tutorials use "free(image)".
Advertisement
You use the delete operator if you allocated the memory with the new operator... If you used malloc to allocate memory you have to use free...

This topic is closed to new replies.

Advertisement