diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 3e4a3fce0cf..7c9e30d8b33 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -2265,6 +2265,7 @@ ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, size_t *r_width, size_t *r_height) { + ImBuf *ibuf = nullptr; IStream *stream = nullptr; Imf::RgbaInputFile *file = nullptr; @@ -2287,6 +2288,8 @@ ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, file = new RgbaInputFile(*stream, 1); if (!file->isComplete()) { + delete file; + delete stream; return nullptr; } @@ -2318,7 +2321,7 @@ ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, int dest_w = std::max(int(source_w * scale_factor), 1); int dest_h = std::max(int(source_h * scale_factor), 1); - ImBuf *ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_float_data); + ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_float_data); /* A single row of source pixels. */ Imf::Array pixels(source_w); @@ -2354,12 +2357,20 @@ ImBuf *imb_load_filepath_thumbnail_openexr(const char *filepath, catch (const std::exception &exc) { std::cerr << exc.what() << std::endl; + if (ibuf) { + IMB_freeImBuf(ibuf); + } + delete file; delete stream; return nullptr; } catch (...) { /* Catch-all for edge cases or compiler bugs. */ std::cerr << "OpenEXR-Thumbnail: UNKNOWN ERROR" << std::endl; + if (ibuf) { + IMB_freeImBuf(ibuf); + } + delete file; delete stream; return nullptr;