mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 14:13:43 +00:00
loader: fixed potential memory leaks in font handling
Simply loading a font doesn't mean it is in use. Fixed the loader's reference count to prevent incorrect increments.
This commit is contained in:
parent
07da6c5870
commit
4ea95d8707
2 changed files with 10 additions and 2 deletions
|
@ -267,7 +267,11 @@ bool LoaderMgr::term()
|
||||||
auto loader = _activeLoaders.head;
|
auto loader = _activeLoaders.head;
|
||||||
|
|
||||||
//clean up the remained font loaders which is globally used.
|
//clean up the remained font loaders which is globally used.
|
||||||
while (loader && loader->type == FileType::Ttf) {
|
while (loader) {
|
||||||
|
if (loader->type != FileType::Ttf) {
|
||||||
|
loader = loader->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto ret = loader->close();
|
auto ret = loader->close();
|
||||||
auto tmp = loader;
|
auto tmp = loader;
|
||||||
loader = loader->next;
|
loader = loader->next;
|
||||||
|
|
|
@ -62,7 +62,11 @@ Result Text::load(const std::string& path) noexcept
|
||||||
{
|
{
|
||||||
#ifdef THORVG_FILE_IO_SUPPORT
|
#ifdef THORVG_FILE_IO_SUPPORT
|
||||||
bool invalid; //invalid path
|
bool invalid; //invalid path
|
||||||
if (!LoaderMgr::loader(path, &invalid)) {
|
auto loader = LoaderMgr::loader(path, &invalid);
|
||||||
|
if (loader) {
|
||||||
|
if (loader->sharing > 0) --loader->sharing; //font loading doesn't mean sharing.
|
||||||
|
return Result::Success;
|
||||||
|
} else {
|
||||||
if (invalid) return Result::InvalidArguments;
|
if (invalid) return Result::InvalidArguments;
|
||||||
else return Result::NonSupport;
|
else return Result::NonSupport;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue