sent-font

sent: font engine test
git clone git://git.codemadness.org/sent-font
Log | Files | Refs | LICENSE

commit f6455efd52cdcfcb25030a8f3644162e8b861573
parent 67ec8b1547b9e58155f0966731820b25e71240e8
Author: Markus Teich <markus.teich@stusta.mhn.de>
Date:   Wed, 11 Nov 2015 18:49:57 +0100

simplify png cleanup

Diffstat:
sent.c | 24++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/sent.c b/sent.c @@ -79,6 +79,7 @@ typedef struct { } Shortcut; static Image *pngopen(char *filename); +static void pngfree(Image *img); static int pngread(Image *img); static int pngprepare(Image *img); static void pngscale(Image *img); @@ -146,14 +147,9 @@ Image *pngopen(char *filename) free(img); return NULL; } - if (!(img->info_ptr = png_create_info_struct(img->png_ptr))) { - png_destroy_read_struct(&img->png_ptr, NULL, NULL); - free(img); - return NULL; - } - if (setjmp(png_jmpbuf(img->png_ptr))) { - png_destroy_read_struct(&img->png_ptr, &img->info_ptr, NULL); - free(img); + if (!(img->info_ptr = png_create_info_struct(img->png_ptr)) + || setjmp(png_jmpbuf(img->png_ptr))) { + pngfree(img); return NULL; } @@ -167,6 +163,12 @@ Image *pngopen(char *filename) return img; } +void pngfree(Image *img) +{ + png_destroy_read_struct(&img->png_ptr, img->info_ptr ? &img->info_ptr : NULL, NULL); + free(img); +} + int pngread(Image *img) { unsigned int y; @@ -330,6 +332,8 @@ void getfontsize(char *str, unsigned int *width, unsigned int *height) void cleanup() { + unsigned int i; + drw_scm_free(sc); drw_free(d); @@ -337,6 +341,10 @@ void cleanup() XSync(xw.dpy, False); XCloseDisplay(xw.dpy); if (slides) { + for (i = 0; i < slidecount; i++) { + if (slides[i].img) + pngfree(slides[i].img); + } free(slides); slides = NULL; }