]> granicus.if.org Git - openjpeg/commitdiff
Use buffer on stack to read TGA header
authormayeut <mayeut@users.noreply.github.com>
Wed, 23 Sep 2015 19:17:06 +0000 (21:17 +0200)
committermayeut <mayeut@users.noreply.github.com>
Wed, 23 Sep 2015 19:17:06 +0000 (21:17 +0200)
Fixes a potential leak
Fixes #601

src/bin/jp2/convert.c

index a894a369b9c75721a4437dd5621be9e99d3cb185..1ccb34f875e3802ee637c3501fa15f249447f320 100644 (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;