Blame SOURCES/0003-Prevent-a-double-free-in-the-error-code-path.patch

2c1650
From ad5a88046266478c2c9600f6d8a11ab707cb4c7e Mon Sep 17 00:00:00 2001
2c1650
From: Matthieu Herrb <matthieu@herrb.eu>
2c1650
Date: Thu, 12 Jan 2023 15:05:39 +1000
2c1650
Subject: [PATCH libXpm 3/6] Prevent a double free in the error code path
2c1650
2c1650
xpmParseDataAndCreate() calls XDestroyImage() in the error path.
2c1650
Reproducible with sxpm "zero-width.xpm", that file is in the test/
2c1650
directory.
2c1650
2c1650
The same approach is needed in the bytes_per_line == 0 condition though
2c1650
here it just plugs a memory leak.
2c1650
---
2c1650
 src/create.c | 6 +++++-
2c1650
 1 file changed, 5 insertions(+), 1 deletion(-)
2c1650
2c1650
diff --git a/src/create.c b/src/create.c
2c1650
index a750846..0f3735c 100644
2c1650
--- a/src/create.c
2c1650
+++ b/src/create.c
2c1650
@@ -994,11 +994,15 @@ CreateXImage(
2c1650
 #if !defined(FOR_MSW) && !defined(AMIGA)
2c1650
     if (height != 0 && (*image_return)->bytes_per_line >= INT_MAX / height) {
2c1650
 	XDestroyImage(*image_return);
2c1650
+	*image_return = NULL;
2c1650
 	return XpmNoMemory;
2c1650
     }
2c1650
     /* now that bytes_per_line must have been set properly alloc data */
2c1650
-    if((*image_return)->bytes_per_line == 0 ||  height == 0)
2c1650
+    if((*image_return)->bytes_per_line == 0 ||  height == 0) {
2c1650
+	XDestroyImage(*image_return);
2c1650
+	*image_return = NULL;
2c1650
     	return XpmNoMemory;
2c1650
+    }
2c1650
     (*image_return)->data =
2c1650
 	(char *) XpmMalloc((*image_return)->bytes_per_line * height);
2c1650
 
2c1650
-- 
2c1650
2.39.0
2c1650