From f82d7f3a63a99997449b15390d0c3f2fc6159d9c Mon Sep 17 00:00:00 2001 From: mayeut Date: Wed, 23 Sep 2015 21:17:06 +0200 Subject: [PATCH] Use buffer on stack to read TGA header Fixes a potential leak Fixes #601 --- src/bin/jp2/convert.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index a894a369..1ccb34f8 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -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;