From 7a627e644242bdbb00e5cdac4536c64268454af3 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 22:16:58 +0200 Subject: Some small Keyboard.c improvements as in xorg-xserver upstream's hw/xnest/Keyboard.c --- nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c index 758ec9275..51a11b4f4 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c @@ -704,7 +704,7 @@ int nxagentKeyboardProc(DeviceIntPtr pDev, int onoff) int mapWidth; int min_keycode, max_keycode; KeySymsRec keySyms; - CARD8 modmap[256]; + CARD8 modmap[MAP_LENGTH]; int i, j; XKeyboardState values; char *model = NULL, *layout = NULL; @@ -765,7 +765,7 @@ N/A #ifdef _XSERVER64 { KeySym64 *keymap64; - int i, len; + int len; keymap64 = XGetKeyboardMapping(nxagentDisplay, min_keycode, max_keycode - min_keycode + 1, @@ -807,8 +807,7 @@ N/A nxagentCapsMask = 0; nxagentNumlockMask = 0; - for (i = 0; i < 256; i++) - modmap[i] = 0; + memset(modmap, 0, sizeof(modmap)); for (j = 0; j < 8; j++) for(i = 0; i < modifier_keymap->max_keypermod; i++) { CARD8 keycode; @@ -823,6 +822,7 @@ N/A } } XFreeModifiermap(modifier_keymap); + modifier_keymap = NULL; nxagentCheckRemoteKeycodes(); -- cgit v1.2.3 From 1e3db85a026338e5a56de9f75bddeff283ba24fb Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 21:46:52 +0200 Subject: Fix some valgrind findings Some of them have not been seen in the wild yet. Partly fixes ArcticaProject/nx-libs#711 --- nx-X11/programs/Xserver/dix/devices.c | 18 ++++++++---------- nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c | 8 +++----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/nx-X11/programs/Xserver/dix/devices.c b/nx-X11/programs/Xserver/dix/devices.c index 1c7572d64..d31ff8224 100644 --- a/nx-X11/programs/Xserver/dix/devices.c +++ b/nx-X11/programs/Xserver/dix/devices.c @@ -908,7 +908,7 @@ AllModifierKeysAreUp(dev, map1, per1, map2, per2) int ProcSetModifierMapping(ClientPtr client) { - xSetModifierMappingReply rep; + xSetModifierMappingReply rep = {0}; REQUEST(xSetModifierMappingReq); KeyCode *inputMap; int inputMapLen; @@ -1016,11 +1016,10 @@ ProcSetModifierMapping(ClientPtr client) int ProcGetModifierMapping(ClientPtr client) { - xGetModifierMappingReply rep; + xGetModifierMappingReply rep = {0}; register KeyClassPtr keyc = inputInfo.keyboard->key; REQUEST_SIZE_MATCH(xReq); - memset(&rep, 0, sizeof(xGetModifierMappingReply)); rep.type = X_Reply; rep.numKeyPerModifier = keyc->maxKeysPerModifier; rep.sequenceNumber = client->sequence; @@ -1082,7 +1081,7 @@ ProcSetPointerMapping(ClientPtr client) { REQUEST(xSetPointerMappingReq); BYTE *map; - xSetPointerMappingReply rep; + xSetPointerMappingReply rep = {0}; register unsigned int i; DeviceIntPtr mouse = inputInfo.pointer; @@ -1119,7 +1118,7 @@ ProcSetPointerMapping(ClientPtr client) int ProcGetKeyboardMapping(ClientPtr client) { - xGetKeyboardMappingReply rep; + xGetKeyboardMappingReply rep = {0}; REQUEST(xGetKeyboardMappingReq); KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms; @@ -1138,7 +1137,6 @@ ProcGetKeyboardMapping(ClientPtr client) return BadValue; } - memset(&rep, 0, sizeof(xGetKeyboardMappingReply)); rep.type = X_Reply; rep.sequenceNumber = client->sequence; rep.keySymsPerKeyCode = curKeySyms->mapWidth; @@ -1387,7 +1385,7 @@ ProcGetKeyboardControl (ClientPtr client) { int i; register KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl; - xGetKeyboardControlReply rep; + xGetKeyboardControlReply rep = {0}; REQUEST_SIZE_MATCH(xReq); rep.type = X_Reply; @@ -1492,7 +1490,7 @@ int ProcGetPointerControl(ClientPtr client) { register PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl; - xGetPointerControlReply rep; + xGetPointerControlReply rep = {0}; REQUEST_SIZE_MATCH(xReq); rep.type = X_Reply; @@ -1526,7 +1524,7 @@ ProcGetMotionEvents(ClientPtr client) { WindowPtr pWin; xTimecoord * coords = (xTimecoord *) NULL; - xGetMotionEventsReply rep; + xGetMotionEventsReply rep = {0}; int i, count, xmin, xmax, ymin, ymax; unsigned long nEvents; DeviceIntPtr mouse = inputInfo.pointer; @@ -1591,7 +1589,7 @@ ProcGetMotionEvents(ClientPtr client) int ProcQueryKeymap(ClientPtr client) { - xQueryKeymapReply rep; + xQueryKeymapReply rep = {0}; int i; CARD8 *down = inputInfo.keyboard->key->down; diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c index e59144f94..dba734ad7 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c @@ -361,7 +361,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) int nnames; int stringLens; int i; - xListFontsReply reply; + xListFontsReply reply = {0}; char *bufptr; char *bufferStart; int aliascount = 0; @@ -602,13 +602,12 @@ finish: for (i = 0; i < nnames; i++) stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - memset(&reply, 0, sizeof(xListFontsReply)); reply.type = X_Reply; reply.length = (stringLens + nnames + 3) >> 2; reply.nFonts = nnames; reply.sequenceNumber = client->sequence; - bufptr = bufferStart = (char *) malloc(reply.length << 2); + bufptr = bufferStart = (char *) calloc(1, reply.length << 2); if (!bufptr && reply.length) { SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); @@ -744,7 +743,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) xFontProp *pFP; int i; int aliascount = 0; - xListFontsWithInfoReply finalReply; + xListFontsWithInfoReply finalReply = {0}; if (client->clientGone) { @@ -967,7 +966,6 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) } finish: length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); finalReply.type = X_Reply; finalReply.sequenceNumber = client->sequence; finalReply.length = (sizeof(xListFontsWithInfoReply) -- cgit v1.2.3 From 389e3a4459e3b61eea3a21aba560122dbca264e6 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 22:08:08 +0200 Subject: ProcGetPointerMapping uses rep.nElts before it is initialized Backport of this xorg upstream commit (with omitting the mentioned d792ac125a0462a04a930af543cbc732f8cdab7d). commit 34cf559bcf99dad550527b5ff53f247f0e8e73ee Author: Keith Packard Date: Tue Jul 10 15:58:48 2012 -0700 ProcGetPointerMapping uses rep.nElts before it is initialized In: commit d792ac125a0462a04a930af543cbc732f8cdab7d Author: Alan Coopersmith Date: Mon Jul 9 19:12:43 2012 -0700 Use C99 designated initializers in dix Replies the initializer for the .length element of the xGetPointerMappingReply structure uses the value of rep.nElts, but that won't be set until after this initializer runs, so we get garbage in the length element and clients using it will generally wedge. Easy to verify: $ xmodmap -pp Fixed by creating a local nElts variable and using that. Signed-off-by: Keith Packard Reviewed-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/programs/Xserver/dix/devices.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nx-X11/programs/Xserver/dix/devices.c b/nx-X11/programs/Xserver/dix/devices.c index d31ff8224..51cf3fef9 100644 --- a/nx-X11/programs/Xserver/dix/devices.c +++ b/nx-X11/programs/Xserver/dix/devices.c @@ -1156,17 +1156,20 @@ ProcGetKeyboardMapping(ClientPtr client) int ProcGetPointerMapping(ClientPtr client) { + int nElts; xGetPointerMappingReply rep = {0}; ButtonClassPtr butc = inputInfo.pointer->button; + nElts = (butc) ? butc->numButtons : 0; REQUEST_SIZE_MATCH(xReq); rep.type = X_Reply; + rep.nElts = nElts; rep.sequenceNumber = client->sequence; - rep.nElts = butc->numButtons; - rep.length = ((unsigned)rep.nElts + (4-1))/4; + rep.length = ((unsigned)nElts + (4-1))/4; WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep); - WriteToClient(client, (int)rep.nElts, &butc->map[1]); + if (butc) + WriteToClient(client, nElts, &butc->map[1]); return Success; } -- cgit v1.2.3 From e5975a70e8e03e58f102e8e238143d22cd4d1ed5 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 23:05:05 +0200 Subject: os/io.c: fix unitialised bytes ... by implementing some kind of recalloc (mix of realloc and calloc). Fixes this valgrind finding: ==7061== Syscall param writev(vector[...]) points to uninitialised byte(s) ==7061== at 0x781EFE0: __writev_nocancel (syscall-template.S:84) ==7061== by 0x488974: _XSERVTransSocketWritev (Xtranssock.c:2914) ==7061== by 0x47DBD3: FlushClient (io.c:1080) ==7061== by 0x47DBD3: FlushAllOutput.part.0 (io.c:817) ==7061== by 0x477304: WaitForSomething (WaitFor.c:246) ==7061== by 0x434369: Dispatch (NXdispatch.c:360) ==7061== by 0x40EB92: main (main.c:353) ==7061== Address 0x102106f3 is 50,211 bytes inside a block of size 54,308 alloc'd ==7061== at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==7061== by 0x47F08F: FlushClient (io.c:1123) ==7061== by 0x47F307: WriteToClient (io.c:991) ==7061== by 0x42903C: doListFontsAndAliases (NXdixfonts.c:660) ==7061== by 0x42B7D6: ListFonts (NXdixfonts.c:735) ==7061== by 0x433A6D: ProcListFonts (NXdispatch.c:989) ==7061== by 0x4344A5: Dispatch (NXdispatch.c:482) ==7061== by 0x40EB92: main (main.c:353) ==7061== Uninitialised value was created by a heap allocation ==7061== at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==7061== by 0x47F08F: FlushClient (io.c:1123) ==7061== by 0x47F307: WriteToClient (io.c:991) ==7061== by 0x42903C: doListFontsAndAliases (NXdixfonts.c:660) ==7061== by 0x42B7D6: ListFonts (NXdixfonts.c:735) ==7061== by 0x433A6D: ProcListFonts (NXdispatch.c:989) ==7061== by 0x4344A5: Dispatch (NXdispatch.c:482) ==7061== by 0x40EB92: main (main.c:353) ==7061== --- nx-X11/programs/Xserver/os/io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/os/io.c b/nx-X11/programs/Xserver/os/io.c index 07399438e..6eeee349a 100644 --- a/nx-X11/programs/Xserver/os/io.c +++ b/nx-X11/programs/Xserver/os/io.c @@ -1120,7 +1120,12 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount) unsigned char *obuf = NULL; if (notWritten + BUFSIZE <= INT_MAX) { - obuf = realloc(oco->buf, notWritten + BUFSIZE); + obuf = calloc(1, notWritten + BUFSIZE); + if (obuf) + { + memmove(obuf, oco->buf, oco->size); + free(oco->buf); + } } if (!obuf) { -- cgit v1.2.3 From cfcaa442d19f017f7485cc0ea4101f2652c2db4f Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 23:14:41 +0200 Subject: xkb/xkb.c: init all reply structs and do it identically everywhere. As we are using C99 designated initializers here we remove the memset and bzero calls that had been used for this at some locations. --- nx-X11/programs/Xserver/xkb/xkb.c | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/nx-X11/programs/Xserver/xkb/xkb.c b/nx-X11/programs/Xserver/xkb/xkb.c index 8a96ec17d..987ebcd7b 100644 --- a/nx-X11/programs/Xserver/xkb/xkb.c +++ b/nx-X11/programs/Xserver/xkb/xkb.c @@ -159,7 +159,7 @@ int ProcXkbUseExtension(ClientPtr client) { REQUEST(xkbUseExtensionReq); - xkbUseExtensionReply rep; + xkbUseExtensionReply rep = {0}; int supported; REQUEST_SIZE_MATCH(xkbUseExtensionReq); @@ -187,7 +187,6 @@ ProcXkbUseExtension(ClientPtr client) stuff->wantedMajor,stuff->wantedMinor, SERVER_XKB_MAJOR_VERSION,SERVER_XKB_MINOR_VERSION); } - memset(&rep, 0, sizeof(xkbUseExtensionReply)); rep.type = X_Reply; rep.supported = supported; rep.length = 0; @@ -502,7 +501,7 @@ ProcXkbGetState(ClientPtr client) { REQUEST(xkbGetStateReq); DeviceIntPtr dev; - xkbGetStateReply rep; + xkbGetStateReply rep = {0}; XkbStateRec *xkb; REQUEST_SIZE_MATCH(xkbGetStateReq); @@ -513,7 +512,6 @@ ProcXkbGetState(ClientPtr client) CHK_KBD_DEVICE(dev,stuff->deviceSpec); xkb= &dev->key->xkbInfo->state; - bzero(&rep,sizeof(xkbGetStateReply)); rep.type= X_Reply; rep.sequenceNumber= client->sequence; rep.length = 0; @@ -1350,7 +1348,7 @@ int ProcXkbGetMap(ClientPtr client) { DeviceIntPtr dev; - xkbGetMapReply rep; + xkbGetMapReply rep = {0}; XkbDescRec *xkb; int n,status; @@ -1366,7 +1364,6 @@ ProcXkbGetMap(ClientPtr client) CHK_MASK_LEGAL(0x03,stuff->partial,XkbAllMapComponentsMask); xkb= dev->key->xkbInfo->desc; - bzero(&rep,sizeof(xkbGetMapReply)); rep.type= X_Reply; rep.sequenceNumber= client->sequence; rep.length = (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply))>>2; @@ -2542,7 +2539,7 @@ int size; int ProcXkbGetCompatMap(ClientPtr client) { - xkbGetCompatMapReply rep; + xkbGetCompatMapReply rep = {0}; DeviceIntPtr dev; XkbDescPtr xkb; XkbCompatMapPtr compat; @@ -2718,7 +2715,7 @@ ProcXkbSetCompatMap(ClientPtr client) int ProcXkbGetIndicatorState(ClientPtr client) { - xkbGetIndicatorStateReply rep; + xkbGetIndicatorStateReply rep = {0};; XkbSrvLedInfoPtr sli; DeviceIntPtr dev; @@ -2827,7 +2824,7 @@ register unsigned bit; int ProcXkbGetIndicatorMap(ClientPtr client) { -xkbGetIndicatorMapReply rep; + xkbGetIndicatorMapReply rep = {0}; DeviceIntPtr dev; XkbDescPtr xkb; XkbIndicatorPtr leds; @@ -2937,7 +2934,7 @@ int ProcXkbGetNamedIndicator(ClientPtr client) { DeviceIntPtr dev; - xkbGetNamedIndicatorReply rep; + xkbGetNamedIndicatorReply rep = {0}; register int i = 0; XkbSrvLedInfoPtr sli; XkbIndicatorMapPtr map = NULL; @@ -3438,7 +3435,7 @@ ProcXkbGetNames(ClientPtr client) { DeviceIntPtr dev; XkbDescPtr xkb; - xkbGetNamesReply rep; + xkbGetNamesReply rep = {0}; REQUEST(xkbGetNamesReq); REQUEST_SIZE_MATCH(xkbGetNamesReq); @@ -3450,7 +3447,6 @@ ProcXkbGetNames(ClientPtr client) CHK_MASK_LEGAL(0x01,stuff->which,XkbAllNamesMask); xkb = dev->key->xkbInfo->desc; - memset(&rep, 0, sizeof(xkbGetNamesReply)); rep.type= X_Reply; rep.sequenceNumber= client->sequence; rep.length = 0; @@ -4368,7 +4364,7 @@ int ProcXkbGetGeometry(ClientPtr client) { DeviceIntPtr dev; - xkbGetGeometryReply rep; + xkbGetGeometryReply rep = {0}; XkbGeometryPtr geom; Bool shouldFree; Status status; @@ -4907,7 +4903,7 @@ int ProcXkbPerClientFlags(ClientPtr client) { DeviceIntPtr dev; - xkbPerClientFlagsReply rep; + xkbPerClientFlagsReply rep = {0}; XkbInterestPtr interest; REQUEST(xkbPerClientFlagsReq); @@ -4921,7 +4917,6 @@ ProcXkbPerClientFlags(ClientPtr client) CHK_MASK_MATCH(0x02,stuff->change,stuff->value); interest = XkbFindClientResource((DevicePtr)dev,client); - memset(&rep, 0, sizeof(xkbPerClientFlagsReply)); rep.type= X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; @@ -5040,7 +5035,7 @@ int ProcXkbListComponents(ClientPtr client) { DeviceIntPtr dev; - xkbListComponentsReply rep; + xkbListComponentsReply rep = {0}; unsigned len; int status; unsigned char * str; @@ -5076,7 +5071,6 @@ ProcXkbListComponents(ClientPtr client) } return status; } - bzero(&rep,sizeof(xkbListComponentsReply)); rep.type= X_Reply; rep.deviceID = dev->id; rep.sequenceNumber = client->sequence; @@ -5117,12 +5111,12 @@ ProcXkbGetKbdByName(ClientPtr client) { DeviceIntPtr dev; XkbFileInfo finfo; - xkbGetKbdByNameReply rep; - xkbGetMapReply mrep; - xkbGetCompatMapReply crep; - xkbGetIndicatorMapReply irep; - xkbGetNamesReply nrep; - xkbGetGeometryReply grep; + xkbGetKbdByNameReply rep = {0}; + xkbGetMapReply mrep = {0}; + xkbGetCompatMapReply crep = {0}; + xkbGetIndicatorMapReply irep = {0}; + xkbGetNamesReply nrep = {0}; + xkbGetGeometryReply grep = {0}; XkbComponentNamesRec names; XkbDescPtr xkb; unsigned char * str; @@ -5641,7 +5635,7 @@ int ProcXkbGetDeviceInfo(ClientPtr client) { DeviceIntPtr dev; -xkbGetDeviceInfoReply rep; +xkbGetDeviceInfoReply rep = {0}; int status,nDeviceLedFBs; unsigned length,nameLen; CARD16 ledClass,ledID; @@ -5666,7 +5660,6 @@ char * str; wanted&= ~XkbXIUnsupported; nameLen= XkbSizeCountedString(dev->name); - bzero((char *)&rep,SIZEOF(xkbGetDeviceInfoReply)); rep.type = X_Reply; rep.deviceID= dev->id; rep.sequenceNumber = client->sequence; @@ -6059,7 +6052,7 @@ int ProcXkbSetDebuggingFlags(ClientPtr client) { CARD32 newFlags,newCtrls,extraLength; -xkbSetDebuggingFlagsReply rep; +xkbSetDebuggingFlagsReply rep = {0}; REQUEST(xkbSetDebuggingFlagsReq); REQUEST_AT_LEAST_SIZE(xkbSetDebuggingFlagsReq); -- cgit v1.2.3 From e0291f30df9df99bfbd987e7d181237925d3c0e3 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 23:18:36 +0200 Subject: NXdixfonts.c: use calloc for LFclosurePtr Just to be sure. It is used at lots of locations afterwards. --- nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c index dba734ad7..8b3fdcc8d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c @@ -690,7 +690,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, if (length > XLFDMAXFONTNAMELEN) return BadAlloc; - if (!(c = (LFclosurePtr) malloc(sizeof *c))) + if (!(c = (LFclosurePtr) calloc(1, sizeof *c))) return BadAlloc; c->fpe_list = (FontPathElementPtr *) malloc(sizeof(FontPathElementPtr) * num_fpes); -- cgit v1.2.3 From a2008b28ed657292f53e96e0ab03ce99f56cf1f6 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 21 Jun 2018 23:30:34 +0200 Subject: NXdixfonts.c: free() can handle NULL so let's remove some superflous tests --- nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c index 8b3fdcc8d..50bf719c6 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c +++ b/nx-X11/programs/Xserver/hw/nxagent/NXdixfonts.c @@ -478,7 +478,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) return TRUE; } if (err == FontNameAlias) { - if (resolved) free(resolved); + free(resolved); resolved = (char *) malloc(resolvedlen + 1); if (resolved) memmove(resolved, tmpname, resolvedlen + 1); @@ -544,8 +544,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) { c->saved = c->current; c->haveSaved = TRUE; - if (c->savedName) - free(c->savedName); + free(c->savedName); c->savedName = (char *)malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); @@ -663,14 +662,14 @@ bail: for (i = 0; i < c->num_fpes; i++) FreeFPE(c->fpe_list[i]); free(c->fpe_list); - if (c->savedName) free(c->savedName); + free(c->savedName); #ifdef HAS_XFONT2 xfont2_free_font_names(names); #else FreeFontNames(names); #endif /* HAS_XFONT2 */ free(c); - if (resolved) free(resolved); + free(resolved); return TRUE; } @@ -856,8 +855,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) c->saved = c->current; c->haveSaved = TRUE; c->savedNumFonts = numFonts; - if (c->savedName) - free(c->savedName); + free(c->savedName); c->savedName = (char *)malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); @@ -983,7 +981,7 @@ bail: FreeFPE(c->fpe_list[i]); free(c->reply); free(c->fpe_list); - if (c->savedName) free(c->savedName); + free(c->savedName); free(c); return TRUE; } @@ -1201,7 +1199,7 @@ nxdoListFontsAndAliases(client, fss) return TRUE; } if (err == FontNameAlias) { - if (resolved) free(resolved); + free(resolved); resolved = (char *) malloc(resolvedlen + 1); if (resolved) { @@ -1273,8 +1271,7 @@ nxdoListFontsAndAliases(client, fss) { c->saved = c->current; c->haveSaved = TRUE; - if (c->savedName) - free(c->savedName); + free(c->savedName); c->savedName = (char *)malloc(namelen + 1); if (c->savedName) { @@ -1370,7 +1367,7 @@ finish: for (i = 0; i < c->num_fpes; i++) FreeFPE(c->fpe_list[i]); free(c->fpe_list); - if (c->savedName) free(c->savedName); + free(c->savedName); #ifdef HAS_XFONT2 xfont2_free_font_names(c->names); #else @@ -1378,7 +1375,7 @@ finish: #endif /* HAS_XFONT2 */ free(c); free(fss); - if (resolved) free(resolved); + free(resolved); return doOpenFont(client, oc); } -- cgit v1.2.3 From 59e46dc54e4fa7590a058e58bb121c1e4de992eb Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 3 Jul 2018 16:17:56 +0200 Subject: dix/dixfonts.c: free() can handle NULL so let's remove some superflous tests --- nx-X11/programs/Xserver/dix/dixfonts.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nx-X11/programs/Xserver/dix/dixfonts.c b/nx-X11/programs/Xserver/dix/dixfonts.c index 0d90cd7b0..752a7eb6d 100644 --- a/nx-X11/programs/Xserver/dix/dixfonts.c +++ b/nx-X11/programs/Xserver/dix/dixfonts.c @@ -741,7 +741,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) return TRUE; } if (err == FontNameAlias) { - if (resolved) free(resolved); + free(resolved); resolved = (char *) malloc(resolvedlen + 1); if (resolved) memmove(resolved, tmpname, resolvedlen + 1); @@ -807,8 +807,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) { c->saved = c->current; c->haveSaved = TRUE; - if (c->savedName) - free(c->savedName); + free(c->savedName); c->savedName = (char *)malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); @@ -904,14 +903,14 @@ bail: for (i = 0; i < c->num_fpes; i++) FreeFPE(c->fpe_list[i]); free(c->fpe_list); - if (c->savedName) free(c->savedName); + free(c->savedName); #ifdef HAS_XFONT2 xfont2_free_font_names(names); #else FreeFontNames(names); #endif /* HAS_XFONT2 */ free(c); - if (resolved) free(resolved); + free(resolved); return TRUE; } @@ -1091,8 +1090,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) c->saved = c->current; c->haveSaved = TRUE; c->savedNumFonts = numFonts; - if (c->savedName) - free(c->savedName); + free(c->savedName); c->savedName = (char *)malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); @@ -1203,7 +1201,7 @@ bail: FreeFPE(c->fpe_list[i]); free(c->reply); free(c->fpe_list); - if (c->savedName) free(c->savedName); + free(c->savedName); free(c); return TRUE; } -- cgit v1.2.3 From b394eac8f79773dbe8e40f62e2aeb5c49bf7f65d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 3 Jul 2018 16:19:21 +0200 Subject: dixfonts.c: use calloc for LFclosurePtr ... to keep dix/dixfonts and hw/nxagnet/NXdixfonts.c in sync. --- nx-X11/programs/Xserver/dix/dixfonts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx-X11/programs/Xserver/dix/dixfonts.c b/nx-X11/programs/Xserver/dix/dixfonts.c index 752a7eb6d..b16b6b2e6 100644 --- a/nx-X11/programs/Xserver/dix/dixfonts.c +++ b/nx-X11/programs/Xserver/dix/dixfonts.c @@ -930,7 +930,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, if (length > XLFDMAXFONTNAMELEN) return BadAlloc; - if (!(c = (LFclosurePtr) malloc(sizeof *c))) + if (!(c = (LFclosurePtr) calloc(1, sizeof *c))) return BadAlloc; c->fpe_list = (FontPathElementPtr *) malloc(sizeof(FontPathElementPtr) * num_fpes); -- cgit v1.2.3