mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-08-11 07:39:26 +00:00
Fix memory leak of stb_image data.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user