aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-03 20:06:20 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-03 20:06:24 +0200
commit0cf9f4bcd0697264f887fde7ce7117715e728b36 (patch)
tree38bda56e5cb59cca51cd6a8d1a6b1ee89d924761 /src/Cache.cpp
parentccb89261bd51e448124c462f289d43afcd9006de (diff)
Remove gif file data if gif fails to load
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index df97174..a4c740f 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -110,9 +110,10 @@ namespace dchat
ImageByUrlResult loadImageFromFile(const boost::filesystem::path &filepath)
{
+ StringView fileContent;
try
{
- StringView fileContent = getFileContent(filepath);
+ fileContent = getFileContent(filepath);
if(Gif::isDataGif(fileContent))
{
Gif *gif = new Gif(move(fileContent));
@@ -124,17 +125,20 @@ namespace dchat
if(texture->loadFromMemory(fileContent.data, fileContent.size))
{
delete fileContent.data;
+ fileContent.data = nullptr;
texture->setSmooth(true);
texture->generateMipmap();
return { texture, ImageByUrlResult::Type::CACHED };
}
delete texture;
delete fileContent.data;
+ fileContent.data = nullptr;
}
}
catch(std::exception &e)
{
fprintf(stderr, "Failed to load image %s, reason: %s\n", filepath.string().c_str(), e.what());
+ delete fileContent.data;
}
return { (sf::Texture*)nullptr, ImageByUrlResult::Type::FAILED_DOWNLOAD };
}