From e362f034464dd81d3c0f423f3358e07e39d9f0dc Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sun, 14 Jan 2024 13:45:57 -0800 Subject: [PATCH] Avoid file descriptor resource leakage in STB source. --- src/stb-image-source.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/stb-image-source.cc b/src/stb-image-source.cc index 764b997..88e2ca5 100644 --- a/src/stb-image-source.cc +++ b/src/stb-image-source.cc @@ -111,7 +111,10 @@ bool STBImageSource::LoadAndScale(const DisplayOptions &options, int w, h; uint8_t *data = stbi__load_and_postprocess_8bit( &context, &w, &h, &channels, kDesiredChannels); - if (!data) return false; + if (!data) { + fclose(img_file); + return false; + } orig_width_ = w; orig_height_ = h; @@ -130,6 +133,8 @@ bool STBImageSource::LoadAndScale(const DisplayOptions &options, ? (int)frames_.size() : std::min(frame_count, (int)frames_.size()); + fclose(img_file); + return !frames_.empty(); }