From 4be2f888f74bcefed2c682d561831bd32f52091b Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 24 Nov 2016 16:20:34 +0900 Subject: [PATCH] Fix memory leak of stb_image data. --- tiny_gltf_loader.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 0223005..109147c 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -893,6 +893,7 @@ static bool LoadImageData(Image *image, std::string *err, int req_width, } if (w < 1 || h < 1) { + free(data); if (err) { (*err) += "Unknown image format.\n"; } @@ -901,6 +902,7 @@ static bool LoadImageData(Image *image, std::string *err, int req_width, if (req_width > 0) { if (req_width != w) { + free(data); if (err) { (*err) += "Image width mismatch.\n"; } @@ -910,6 +912,7 @@ static bool LoadImageData(Image *image, std::string *err, int req_width, if (req_height > 0) { if (req_height != h) { + free(data); if (err) { (*err) += "Image height mismatch.\n"; } @@ -923,6 +926,8 @@ static bool LoadImageData(Image *image, std::string *err, int req_width, image->image.resize(static_cast(w * h * comp)); std::copy(data, data + w * h * comp, image->image.begin()); + free(data); + return true; }