[hackers] [sent] simplify png cleanup || Markus Teich

From: <git_AT_suckless.org>
Date: Wed, 11 Nov 2015 19:15:33 +0100 (CET)

commit f6455efd52cdcfcb25030a8f3644162e8b861573
Author: Markus Teich <markus.teich_AT_stusta.mhn.de>
AuthorDate: Wed Nov 11 18:49:57 2015 +0100
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Wed Nov 11 18:50:46 2015 +0100

    simplify png cleanup

diff --git a/sent.c b/sent.c
index 50dee4c..a263aaf 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -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);
_AT_@ -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;
         }
 
_AT_@ -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;
_AT_@ -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);
 
_AT_@ -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;
         }
Received on Wed Nov 11 2015 - 19:15:33 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 11 2015 - 19:24:14 CET