From 16148abf5eac0e52464ab0fc589c805728790dd2 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 18 Jul 2019 01:15:59 -0400 Subject: image_destroy(): Close file stream --- diff --git a/src/image.c b/src/image.c index 2c1da2a..d85c9fd 100644 --- a/src/image.c +++ b/src/image.c @@ -31,6 +31,7 @@ #include "text.h" struct image { + FILE *fp; png_structp png_ptr; png_infop info_ptr; }; @@ -39,15 +40,14 @@ struct image * image_new(const char *file_name) { struct image *image; - FILE *fp; image = calloc(1, sizeof(*image)); if (!image) { return NULL; } - fp = fopen(file_name, "wb"); - if (!fp) { + image->fp = fopen(file_name, "wb"); + if (!image->fp) { printf(_("Error: Cannot open \"%s\" for writing\n"), file_name); return image_destroy(&image); } @@ -63,7 +63,7 @@ image_new(const char *file_name) return image_destroy(&image); } - png_init_io(image->png_ptr, fp); + png_init_io(image->png_ptr, image->fp); return image; } @@ -107,6 +107,7 @@ image_destroy(struct image **image_p) image = *image_p; + fclose(image->fp); png_destroy_write_struct(&image->png_ptr, &image->info_ptr); free(image); return image = NULL; -- cgit v0.9.1