mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
loader png: fix all memory leaks.
These were detected by asan with PicturePng example, fixed them all.
This commit is contained in:
parent
246149e91a
commit
9434923529
1 changed files with 7 additions and 2 deletions
|
@ -72,6 +72,7 @@ PngLoader::PngLoader()
|
||||||
PngLoader::~PngLoader()
|
PngLoader::~PngLoader()
|
||||||
{
|
{
|
||||||
if (freeData) free(data);
|
if (freeData) free(data);
|
||||||
|
free(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
lodepng_state_init(&state);
|
lodepng_state_init(&state);
|
||||||
|
|
||||||
unsigned int width, height;
|
unsigned int width, height;
|
||||||
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
|
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
|
||||||
|
|
||||||
|
@ -180,10 +181,14 @@ unique_ptr<Surface> PngLoader::bitmap()
|
||||||
|
|
||||||
void PngLoader::run(unsigned tid)
|
void PngLoader::run(unsigned tid)
|
||||||
{
|
{
|
||||||
|
if (image) {
|
||||||
|
free(image);
|
||||||
|
image = nullptr;
|
||||||
|
}
|
||||||
auto width = static_cast<unsigned>(w);
|
auto width = static_cast<unsigned>(w);
|
||||||
auto height = static_cast<unsigned>(h);
|
auto height = static_cast<unsigned>(h);
|
||||||
|
|
||||||
lodepng_decode(&image, &width, &height, &state, data, size);
|
lodepng_decode(&image, &width, &height, &state, data, size);
|
||||||
|
|
||||||
_premultiply((uint32_t*)(image), width, height);
|
_premultiply((uint32_t*)(image), width, height);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue