fix memleaks
This commit is contained in:
@@ -588,21 +588,32 @@ SDL_Surface *mySDL_LoadSurface( CString file )
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
SurfaceHeader h;
|
SurfaceHeader h;
|
||||||
if(fread(&h, sizeof(h), 1, f) != 1) return NULL;
|
if( fread(&h, sizeof(h), 1, f) != 1 )
|
||||||
|
{
|
||||||
|
fclose(f);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Color palette[256];
|
SDL_Color palette[256];
|
||||||
if(h.bpp == 8)
|
if(h.bpp == 8)
|
||||||
if(fread(palette, 256 * sizeof(SDL_Color), 1, f) != 1) return NULL;
|
if( fread(palette, 256 * sizeof(SDL_Color), 1, f) != 1 )
|
||||||
|
{
|
||||||
int size = h.height * h.pitch;
|
fclose(f);
|
||||||
char *pixels = (char *) malloc(size);
|
return NULL;
|
||||||
if(fread(pixels, size, 1, f) != 1) return NULL;
|
}
|
||||||
|
|
||||||
/* Create the surface. */
|
/* Create the surface. */
|
||||||
SDL_Surface *img = SDL_CreateRGBSurfaceFrom(pixels,
|
SDL_Surface *img = SDL_CreateRGBSurface(
|
||||||
h.width, h.height, h.bpp, h.pitch,
|
h.width, h.height, h.bpp, h.pitch,
|
||||||
h.Rmask, h.Gmask, h.Bmask, h.Amask);
|
h.Rmask, h.Gmask, h.Bmask, h.Amask);
|
||||||
|
|
||||||
|
if( fread(img->pixels, h.height * h.pitch, 1, f) != 1 )
|
||||||
|
{
|
||||||
|
fclose(f);
|
||||||
|
SDL_FreeSurface( img );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the palette. */
|
/* Set the palette. */
|
||||||
if( h.bpp == 8 )
|
if( h.bpp == 8 )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user