diff options
author | Benjamin Tissoires <benjamin.tissoires@gmail.com> | 2019-04-11 17:21:17 +0200 |
---|---|---|
committer | Thomas E. Dickey <dickey@his.com> | 2019-04-22 00:16:46 +0000 |
commit | ba4ec937680ee72f2fcd463752766340a4b3729d (patch) | |
tree | 7502ed2fce60f8dd22e93fc175cb7f251bfbdd79 /src | |
parent | 6a7584e0337bb5cfec7f786231597f46c6d5fb16 (diff) |
Fix covscan complain
covscan gets confused by the test before the XtFree.
Error: RESOURCE_LEAK (CWE-772):
libXt-20190411/src/Event.c:743: alloc_fn: Storage is returned from allocation function "__XtMalloc".
libXt-20190411/src/Event.c:743: var_assign: Assigning: "proc" = storage returned from "__XtMalloc((Cardinal)((size_t)numprocs * 16UL))".
libXt-20190411/src/Event.c:745: var_assign: Assigning: "closure" = "proc".
libXt-20190411/src/Event.c:776: leaked_storage: Variable "closure" going out of scope leaks the storage it points to.
libXt-20190411/src/Event.c:776: leaked_storage: Variable "proc" going out of scope leaks the storage it points to.
Mixing static arrays and dynamic ones was a good idea
in the 90s when malloc was expensive, but now, we should
probably make the code clearer by just allocating the
memory when needed.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Event.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/Event.c b/src/Event.c index de52910..d58ee49 100644 --- a/src/Event.c +++ b/src/Event.c @@ -725,8 +725,6 @@ static Boolean CallEventHandlers( register XtEventRec *p; XtEventHandler *proc; XtPointer *closure; - XtEventHandler procs[EHMAXSIZE]; - XtPointer closures[EHMAXSIZE]; Boolean cont_to_disp = True; int i, numprocs; @@ -739,14 +737,10 @@ static Boolean CallEventHandlers( (p->has_type_specifier && event->type == EXT_TYPE(p))) numprocs++; } - if (numprocs > EHMAXSIZE) { - proc = (XtEventHandler *)__XtMalloc((Cardinal)((size_t)numprocs * (sizeof(XtEventHandler) + - sizeof(XtPointer)))); - closure = (XtPointer *)(proc + numprocs); - } else { - proc = procs; - closure = closures; - } + proc = (XtEventHandler *)__XtMalloc((Cardinal)((size_t)numprocs * (sizeof(XtEventHandler) + + sizeof(XtPointer)))); + closure = (XtPointer *)(proc + numprocs); + numprocs = 0; for (p=widget->core.event_table; p; p = p->next) { if ((!p->has_type_specifier && (mask & p->mask)) || @@ -771,8 +765,7 @@ static Boolean CallEventHandlers( */ for (i = 0; i < numprocs && cont_to_disp; i++) (*(proc[i]))(widget, closure[i], event, &cont_to_disp); - if (numprocs > EHMAXSIZE) - XtFree((char *)proc); + XtFree((char *)proc); return cont_to_disp; } |