summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/image.c9
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;