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

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