From c5d4c27a90dfe728e3fdeabd3b3c42e2ec38cca5 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 29 Nov 2014 16:35:17 +0100 Subject: [PATCH] WINGs: to not allocate memory for a short lived array (Coverity #50136) As pointed by Coverity, the array created to temporary store the list of Atoms used in the function 'requestHandler' was leaked. Because this array is very short lived, there is no need to allocate memory for this, it just participates in memory fragmentation. Instead, we use now memory on the stack which is more efficient. Signed-off-by: Christophe CURIS --- WINGs/wtext.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/WINGs/wtext.c b/WINGs/wtext.c index 5981de38..93090e40 100644 --- a/WINGs/wtext.c +++ b/WINGs/wtext.c @@ -2061,15 +2061,14 @@ static WMData *requestHandler(WMView * view, Atom selection, Atom target, void * _TARGETS = XInternAtom(dpy, "TARGETS", False); if (target == _TARGETS) { - Atom *ptr; + Atom array[4]; - ptr = wmalloc(4 * sizeof(Atom)); - ptr[0] = _TARGETS; - ptr[1] = XA_STRING; - ptr[2] = TEXT; - ptr[3] = COMPOUND_TEXT; + array[0] = _TARGETS; + array[1] = XA_STRING; + array[2] = TEXT; + array[3] = COMPOUND_TEXT; - data = WMCreateDataWithBytes(ptr, 4 * 4); + data = WMCreateDataWithBytes(&array, sizeof(array)); WMSetDataFormat(data, 32); *type = target;