mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-07-07 07:21:47 +08:00
Fix memory leak of stb_image data.
This commit is contained in:
parent
15eb9bdf67
commit
4be2f888f7
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user