Skip to content

Commit

Permalink
Fixed more resource leaks
Browse files Browse the repository at this point in the history
GitOrigin-RevId: faaf056a97d8c9394287e7fa606423c507b4403a
  • Loading branch information
Vertexwahn committed May 19, 2024
1 parent 4fcb29a commit 7ad4fe7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions devertexwahn/imaging/io/io_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ReferenceCounted<Image4b> load_image_png_as_Image4b(std::string_view filename) {
if(!info) abort();

if(setjmp(png_jmpbuf(png))) {
fclose(fp);
throw std::runtime_error("Invalid file format");
abort();
}
Expand Down Expand Up @@ -199,14 +200,17 @@ bool store_png(const char *filename, const Image4b &image) {
int height = image.height();

FILE *fp = fopen(filename, "wb");

if (fp == nullptr) {
if (fp != nullptr) fclose(fp);
LOG(INFO) << "Store PNG: Could not open file " << filename;
return false;
}

png_bytep row = nullptr;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == nullptr) {
if (fp != nullptr) fclose(fp);
LOG(ERROR) << "Store PNG: Could not allocate write struct (" << filename << ")";
return false;
}
Expand Down Expand Up @@ -264,6 +268,7 @@ bool store_png(const char *filename, const Image3f &image) {
png_bytep row = nullptr;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == nullptr) {
if (fp != nullptr) fclose(fp);
LOG(ERROR) << "Store PNG: Could not allocate write struct (" << filename << ")";
return false;
}
Expand Down

0 comments on commit 7ad4fe7

Please sign in to comment.