Use buffer on stack to read TGA header

Fixes a potential leak
Fixes #601
This commit is contained in:
mayeut 2015-09-23 21:17:06 +02:00
parent faf63fddad
commit f82d7f3a63
1 changed files with 1 additions and 4 deletions

View File

@ -573,7 +573,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
unsigned int *width, unsigned int *height, int *flip_image)
{
int palette_size;
unsigned char *tga ;
unsigned char tga[TGA_HEADER_SIZE];
unsigned char id_len, /*cmap_type,*/ image_type;
unsigned char pixel_depth, image_desc;
unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size;
@ -581,7 +581,6 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (!bits_per_pixel || !width || !height || !flip_image)
return 0;
tga = (unsigned char*)malloc(18);
if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
@ -605,8 +604,6 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
pixel_depth = (unsigned char)tga[16];
image_desc = (unsigned char)tga[17];
free(tga);
*bits_per_pixel = (unsigned int)pixel_depth;
*width = (unsigned int)image_w;
*height = (unsigned int)image_h;