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

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