progs/util: Fix memory leak if LoadRGBImage fails.

(cherry picked from commit 041cd0e110)
This commit is contained in:
Vinson Lee
2009-11-17 10:11:50 -08:00
parent 84de1672d3
commit f1172c4030

View File

@@ -357,6 +357,7 @@ GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height,
fprintf(stderr,
"Error in LoadRGBImage %d-component images not implemented\n",
image->components );
FreeImage(image);
return NULL;
}
@@ -365,8 +366,10 @@ GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height,
bytes = image->sizeX * image->sizeY * image->components;
buffer = (GLubyte *) malloc(bytes);
if (!buffer)
if (!buffer) {
FreeImage(image);
return NULL;
}
memcpy( (void *) buffer, (void *) image->data, bytes );