loaders: fix memory leak.

While looking for image loader, it occured memory leaks.
Fixed it properly.

@Issues: 178
This commit is contained in:
Hermet Park 2020-12-10 11:57:38 +09:00
parent 393be38f2a
commit 932cc65543
3 changed files with 12 additions and 8 deletions

View file

@ -91,10 +91,10 @@ bool LoaderMgr::term()
unique_ptr<Loader> LoaderMgr::loader(const string& path)
{
auto loader = _find(path);
if (loader && loader->open(path)) return unique_ptr<Loader>(loader);
if (auto loader = _find(path)) {
if (loader->open(path)) return unique_ptr<Loader>(loader);
else delete(loader);
}
return nullptr;
}
@ -103,7 +103,10 @@ unique_ptr<Loader> LoaderMgr::loader(const char* data, uint32_t size)
{
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
auto loader = _find(static_cast<FileType>(i));
if (loader && loader->open(data, size)) return unique_ptr<Loader>(loader);
if (loader) {
if (loader->open(data, size)) return unique_ptr<Loader>(loader);
else delete(loader);
}
}
return nullptr;
}
@ -113,7 +116,10 @@ unique_ptr<Loader> LoaderMgr::loader(uint32_t *data, uint32_t w, uint32_t h, boo
{
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
auto loader = _find(static_cast<FileType>(i));
if (loader && loader->open(data, w, h, copy)) return unique_ptr<Loader>(loader);
if (loader) {
if (loader->open(data, w, h, copy)) return unique_ptr<Loader>(loader);
else delete(loader);
}
}
return nullptr;
}

View file

@ -34,7 +34,6 @@
RawLoader::RawLoader()
{
}

View file

@ -2427,7 +2427,6 @@ static bool _svgLoaderParserForValidCheck(void* data, SimpleXMLType type, const
SvgLoader::SvgLoader()
{
}