Fix: memory leaks in OpenEXR thumbnail loader on error
Delete file and stream when the file is incomplete, and free ibuf when an exception occurs. Found while working on !139739. Ref !139885
This commit is contained in:
committed by
Campbell Barton
parent
c45727c9d0
commit
46f23bd066
@@ -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<Imf::Rgba> 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;
|
||||
|
||||
Reference in New Issue
Block a user