From 0e9106685bfb843473994750cf8c9ea097001cbc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 5 Dec 2022 06:13:04 +0300 Subject: [PATCH] engine: imagelib: img_png: fix Mem_Free on null ptr --- engine/common/imagelib/img_png.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/common/imagelib/img_png.c b/engine/common/imagelib/img_png.c index ac013988..8056ac7c 100644 --- a/engine/common/imagelib/img_png.c +++ b/engine/common/imagelib/img_png.c @@ -214,7 +214,7 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi if( ntohl( crc32 ) != crc32_check ) { Con_DPrintf( S_ERROR "Image_LoadPNG: Found chunk with wrong CRC32 sum (%s)\n", name ); - Mem_Free( idat_buf ); + if( idat_buf ) Mem_Free( idat_buf ); return false; } @@ -222,6 +222,12 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi buf_p += sizeof( crc32 ); } + if( oldsize == 0 ) + { + Con_DPrintf( S_ERROR "Image_LoadPNG: Couldn't find IDAT chunks (%s)\n", name ); + return false; + } + if( png_hdr.ihdr_chunk.colortype == PNG_CT_PALLETE && !pallete ) { Con_DPrintf( S_ERROR "Image_LoadPNG: PLTE chunk not found (%s)\n", name ); @@ -243,12 +249,6 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi return false; } - if( oldsize == 0 ) - { - Con_DPrintf( S_ERROR "Image_LoadPNG: Couldn't find IDAT chunks (%s)\n", name ); - return false; - } - switch( png_hdr.ihdr_chunk.colortype ) { case PNG_CT_GREY: