aboutsummaryrefslogtreecommitdiffstats
path: root/testing/alttab/0001-Fix-memleaks-in-error-case.patch
blob: 730e0fff54cd5725de593b0241a6be34cff7601d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 980bdef0fde36772e283e36a7e12ce28ff1901aa Mon Sep 17 00:00:00 2001
From: Michael Vetter <jubalh@iodoru.org>
Date: Thu, 3 Oct 2019 17:25:19 +0200
Subject: [PATCH] Fix memleaks in error case

We should free img.data.
---
 src/pngd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/pngd.c b/src/pngd.c
index ef46621..fb3fd25 100644
--- a/src/pngd.c
+++ b/src/pngd.c
@@ -250,6 +250,7 @@ int pngReadToDrawable(char *pngpath, Drawable d, uint8_t bg_red,
     fclose(infile);
     if (!img.data || img.width == 0 || img.height == 0) {
         fprintf(stderr, "error loading png data\n");
+        pngFree(&img);
         return 0;
     }
     if (debug > 0)
@@ -259,6 +260,7 @@ int pngReadToDrawable(char *pngpath, Drawable d, uint8_t bg_red,
     pad = 32;
     if (!xdata) {
         fprintf(stderr, "xdata malloc error\n");
+        pngFree(&img);
         return 0;
     }
     ximage =
@@ -267,6 +269,7 @@ int pngReadToDrawable(char *pngpath, Drawable d, uint8_t bg_red,
     if (!ximage) {
         fprintf(stderr, "error creating ximage\n");
         free(xdata);
+        pngFree(&img);
         return 0;
     }
     ximage->byte_order = MSBFirst;
-- 
2.24.0