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