From 2ba029ec8d21d55bfc0954aa89d7539da70bdbdd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 2 Dec 2017 14:02:51 +0100 Subject: [PATCH] - 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. --- src/m_png.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/m_png.cpp b/src/m_png.cpp index 28f015e7b..0f4af87e4 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -383,18 +383,22 @@ PNGHandle *M_VerifyPNG (FileReader *filer, bool takereader) if (filer->Read(&data, 8) != 8) { + if (takereader) delete filer; return NULL; } if (data[0] != MAKE_ID(137,'P','N','G') || data[1] != MAKE_ID(13,10,26,10)) { // Does not have PNG signature + if (takereader) delete filer; return NULL; } if (filer->Read (&data, 8) != 8) { + if (takereader) delete filer; return NULL; } if (data[1] != MAKE_ID('I','H','D','R')) { // IHDR must be the first chunk + if (takereader) delete filer; return NULL; }