]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix an obvious crash in PNG loading
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Oct 2008 14:49:20 +0000 (14:49 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 15 Oct 2008 14:49:20 +0000 (14:49 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8530 d7cf8633-e32d-0410-b094-e92efae38249

image_png.c

index 2dac76faddd5eedc2e28d8e764b75051e55667c1..593bb59419b63a2c495694a7f9780010ff1d7de5 100644 (file)
@@ -340,12 +340,21 @@ unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize)
                        qpng_read_image(png, my_png.FRowPtrs);
                }
                else
-                       Con_DPrintf("PNG_LoadImage : not enough memory\n");
+               {
+                       Con_Printf("PNG_LoadImage : not enough memory\n");
+                       qpng_destroy_read_struct(&png, &pnginfo, 0);
+                       Mem_Free(my_png.FRowPtrs);
+                       return NULL;
+               }
                Mem_Free(my_png.FRowPtrs);
                my_png.FRowPtrs = NULL;
        }
        else
-               Con_DPrintf("PNG_LoadImage : not enough memory\n");
+       {
+               Con_Printf("PNG_LoadImage : not enough memory\n");
+               qpng_destroy_read_struct(&png, &pnginfo, 0);
+               return NULL;
+       }
 
        qpng_read_end(png, pnginfo);
        qpng_destroy_read_struct(&png, &pnginfo, 0);
@@ -357,7 +366,7 @@ unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize)
        {
                Con_Printf ("PNG_LoadImage : bad color depth\n");
                Mem_Free(imagedata);
-               imagedata = NULL;
+               return NULL;
        }
 
        // swizzle RGBA to BGRA