- fixed potential memory leak in M_VerifyPNG.

If the 'takereader' parameter is true, the function must delete the reader if it fails before creating the PNGHandle.
This commit is contained in:
Christoph Oelckers 2017-12-02 14:02:51 +01:00
parent 690e7d8a84
commit 2ba029ec8d

View file

@ -383,18 +383,22 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader)
if (filer->Read(&data, 8) != 8) if (filer->Read(&data, 8) != 8)
{ {
if (takereader) delete filer;
return NULL; return NULL;
} }
if (data[0] != MAKE_ID(137,'P','N','G') || data[1] != MAKE_ID(13,10,26,10)) if (data[0] != MAKE_ID(137,'P','N','G') || data[1] != MAKE_ID(13,10,26,10))
{ // Does not have PNG signature { // Does not have PNG signature
if (takereader) delete filer;
return NULL; return NULL;
} }
if (filer->Read (&data, 8) != 8) if (filer->Read (&data, 8) != 8)
{ {
if (takereader) delete filer;
return NULL; return NULL;
} }
if (data[1] != MAKE_ID('I','H','D','R')) if (data[1] != MAKE_ID('I','H','D','R'))
{ // IHDR must be the first chunk { // IHDR must be the first chunk
if (takereader) delete filer;
return NULL; return NULL;
} }