diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-03 20:21:26 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-03 20:21:29 +0200 |
commit | c0afaebec368af694431c51fa0be1c8952b7e214 (patch) | |
tree | ea8e488c53eb6befb23aa471f2c42fca2ecababa | |
parent | 0cf9f4bcd0697264f887fde7ce7117715e728b36 (diff) |
Perform proper cleanup of gif that failed to load
-rw-r--r-- | src/Cache.cpp | 1 | ||||
-rw-r--r-- | src/Gif.cpp | 21 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index a4c740f..fe377e8 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -138,7 +138,6 @@ namespace dchat 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 }; } diff --git a/src/Gif.cpp b/src/Gif.cpp index 6b38f10..7a80f86 100644 --- a/src/Gif.cpp +++ b/src/Gif.cpp @@ -66,7 +66,16 @@ namespace dchat { throw GifLoadException(e.what()); } - init(); + + try + { + init(); + } + catch(GifLoadException &e) + { + delete fileContent.data; + throw e; + } } Gif::Gif(StringView &&_fileContent) : @@ -74,7 +83,15 @@ namespace dchat currentFrame(0), timeElapsedCs(0.0) { - init(); + try + { + init(); + } + catch(GifLoadException &e) + { + delete fileContent.data; + throw e; + } } void Gif::init() |