Skip to content

Commit

Permalink
Avoid file descriptor resource leakage in STB source.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Jan 14, 2024
1 parent a328e1e commit e362f03
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/stb-image-source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down

0 comments on commit e362f03

Please sign in to comment.