From c0afaebec368af694431c51fa0be1c8952b7e214 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 May 2018 20:21:26 +0200 Subject: Perform proper cleanup of gif that failed to load --- src/Cache.cpp | 1 - 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() -- cgit v1.2.3