diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-18 01:15:59 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-18 01:15:59 (EDT) |
commit | 16148abf5eac0e52464ab0fc589c805728790dd2 (patch) | |
tree | d1119710a0ab5b0743fb13a569a194daebfdb0ea | |
parent | 1a92f0fbcc812ae1fc9e340cfeeda9129e3ff071 (diff) |
image_destroy(): Close file stream
-rw-r--r-- | src/image.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; |