Fix memory leak of stb_image data.

This commit is contained in:
Syoyo Fujita 2016-11-24 16:20:34 +09:00
parent 15eb9bdf67
commit 4be2f888f7

View File

@ -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<size_t>(w * h * comp));
std::copy(data, data + w * h * comp, image->image.begin());
free(data);
return true;
}