Blame SOURCES/0009-Fix-covscan-complain.patch

9f799c
From fa2acae4f13209aaefa5a38d046aca3da545fe63 Mon Sep 17 00:00:00 2001
9f799c
From: Benjamin Tissoires <benjamin.tissoires@gmail.com>
9f799c
Date: Thu, 11 Apr 2019 17:21:17 +0200
9f799c
Subject: [PATCH 9/9] Fix covscan complain
9f799c
9f799c
covscan gets confused by the test before the XtFree.
9f799c
9f799c
Error: RESOURCE_LEAK (CWE-772):
9f799c
libXt-20190411/src/Event.c:743: alloc_fn: Storage is returned from allocation function "__XtMalloc".
9f799c
libXt-20190411/src/Event.c:743: var_assign: Assigning: "proc" = storage returned from "__XtMalloc((Cardinal)((size_t)numprocs * 16UL))".
9f799c
libXt-20190411/src/Event.c:745: var_assign: Assigning: "closure" = "proc".
9f799c
libXt-20190411/src/Event.c:776: leaked_storage: Variable "closure" going out of scope leaks the storage it points to.
9f799c
libXt-20190411/src/Event.c:776: leaked_storage: Variable "proc" going out of scope leaks the storage it points to.
9f799c
9f799c
Mixing static arrays and dynamic ones was a good idea
9f799c
in the 90s when malloc was expensive, but now, we should
9f799c
probably make the code clearer by just allocating the
9f799c
memory when needed.
9f799c
9f799c
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
9f799c
---
9f799c
 src/Event.c | 17 +++++------------
9f799c
 1 file changed, 5 insertions(+), 12 deletions(-)
9f799c
9f799c
diff --git a/src/Event.c b/src/Event.c
9f799c
index 11823d6..c01b65d 100644
9f799c
--- a/src/Event.c
9f799c
+++ b/src/Event.c
9f799c
@@ -725,8 +725,6 @@ static Boolean CallEventHandlers(
9f799c
     register XtEventRec *p;
9f799c
     XtEventHandler *proc;
9f799c
     XtPointer *closure;
9f799c
-    XtEventHandler procs[EHMAXSIZE];
9f799c
-    XtPointer closures[EHMAXSIZE];
9f799c
     Boolean cont_to_disp = True;
9f799c
     int i, numprocs;
9f799c
 
9f799c
@@ -739,14 +737,10 @@ static Boolean CallEventHandlers(
9f799c
 	    (p->has_type_specifier && event->type == EXT_TYPE(p)))
9f799c
 	    numprocs++;
9f799c
     }
9f799c
-    if (numprocs > EHMAXSIZE) {
9f799c
-	proc = (XtEventHandler *)__XtMalloc(numprocs * (sizeof(XtEventHandler) +
9f799c
-						      sizeof(XtPointer)));
9f799c
-	closure = (XtPointer *)(proc + numprocs);
9f799c
-    } else {
9f799c
-	proc = procs;
9f799c
-	closure = closures;
9f799c
-    }
9f799c
+    proc = (XtEventHandler *)__XtMalloc(numprocs * (sizeof(XtEventHandler) +
9f799c
+						   sizeof(XtPointer)));
9f799c
+    closure = (XtPointer *)(proc + numprocs);
9f799c
+
9f799c
     numprocs = 0;
9f799c
     for (p=widget->core.event_table; p; p = p->next) {
9f799c
 	if ((!p->has_type_specifier && (mask & p->mask)) ||
9f799c
@@ -771,8 +765,7 @@ static Boolean CallEventHandlers(
9f799c
 		*/
9f799c
     for (i = 0; i < numprocs && cont_to_disp; i++)
9f799c
 	(*(proc[i]))(widget, closure[i], event, &cont_to_disp);
9f799c
-    if (numprocs > EHMAXSIZE)
9f799c
-	XtFree((char *)proc);
9f799c
+    XtFree((char *)proc);
9f799c
     return cont_to_disp;
9f799c
 }
9f799c
 
9f799c
-- 
9f799c
2.19.2
9f799c