fix more memory leaks

This commit is contained in:
Markus Teich 2015-11-11 19:09:13 +01:00
parent b23121b4aa
commit d7eac23083

8
sent.c
View File

@ -142,6 +142,7 @@ Image *pngopen(char *filename)
return NULL; return NULL;
img = malloc(sizeof(Image)); img = malloc(sizeof(Image));
memset(img, 0, sizeof(Image));
if (!(img->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, if (!(img->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL))) { NULL, NULL))) {
free(img); free(img);
@ -166,6 +167,9 @@ Image *pngopen(char *filename)
void pngfree(Image *img) void pngfree(Image *img)
{ {
png_destroy_read_struct(&img->png_ptr, img->info_ptr ? &img->info_ptr : NULL, NULL); png_destroy_read_struct(&img->png_ptr, img->info_ptr ? &img->info_ptr : NULL, NULL);
free(img->buf);
if (img->ximg)
XDestroyImage(img->ximg);
free(img); free(img);
} }
@ -344,6 +348,8 @@ void cleanup()
XCloseDisplay(xw.dpy); XCloseDisplay(xw.dpy);
if (slides) { if (slides) {
for (i = 0; i < slidecount; i++) { for (i = 0; i < slidecount; i++) {
if (slides[i].text)
free(slides[i].text);
if (slides[i].img) if (slides[i].img)
pngfree(slides[i].img); pngfree(slides[i].img);
} }
@ -408,8 +414,6 @@ void load(FILE *fp)
slides[i].img = 0; slides[i].img = 0;
i++; i++;
} }
if (slides)
slides[i].text = NULL;
slidecount = i; slidecount = i;
} }