From 6592db6bb526f0c43b4c7b55859c629709e039b4 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 16:58:58 +0700 Subject: [PATCH 01/10] Get rid of xstrdup when argument is definitely non-NULL Replace xstrdup with strdup when either constant string is being duplicated or argument is guarded by conditionals and obviously can't be NULL Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- config/config.c | 2 +- config/dbus.c | 8 ++++---- config/hal.c | 14 +++++++------- config/udev.c | 6 +++--- dix/dixfonts.c | 2 +- glx/glxcmds.c | 2 +- glx/glxscreens.c | 6 +++--- xkb/xkbUtils.c | 12 ++++++------ 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/config/config.c b/config/config.c index 65ef679870..d42a16a1fd 100644 --- a/config/config.c +++ b/config/config.c @@ -134,6 +134,6 @@ add_option(InputOption **options, const char *key, const char *value) if (!*options) /* Yeesh. */ return; (*options)->key = xstrdup(key); - (*options)->value = xstrdup(value); + (*options)->value = strdup(value); (*options)->next = NULL; } diff --git a/config/dbus.c b/config/dbus.c index b67fddb3e8..34e3caade9 100644 --- a/config/dbus.c +++ b/config/dbus.c @@ -86,8 +86,8 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) return BadAlloc; } - options->key = xstrdup("_source"); - options->value = xstrdup("client/dbus"); + options->key = strdup("_source"); + options->value = strdup("client/dbus"); if (!options->key || !options->value) { ErrorF("[config/dbus] couldn't allocate first key/value pair\n"); ret = BadAlloc; @@ -120,7 +120,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) tmp); MALFORMED_MESSAGE(); } - options->key = xstrdup(tmp); + options->key = strdup(tmp); if (!options->key) { ErrorF("[config/dbus] couldn't duplicate key!\n"); ret = BadAlloc; @@ -136,7 +136,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) dbus_message_iter_get_basic(&subiter, &tmp); if (!tmp) MALFORMED_MESSAGE(); - options->value = xstrdup(tmp); + options->value = strdup(tmp); if (!options->value) { ErrorF("[config/dbus] couldn't duplicate option!\n"); ret = BadAlloc; diff --git a/config/hal.c b/config/hal.c index 8f9aeb8d39..b70488bf35 100644 --- a/config/hal.c +++ b/config/hal.c @@ -81,7 +81,7 @@ get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name) prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL); LogMessageVerb(X_INFO, 10, "config/hal: getting %s on %s returned %s\n", name, udi, prop ? prop : "(null)"); if (prop) { - ret = xstrdup(prop); + ret = strdup(prop); libhal_free_string(prop); } else { @@ -156,13 +156,13 @@ device_added(LibHalContext *hal_ctx, const char *udi) LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi); goto unwind; } - attrs.device = xstrdup(path); + attrs.device = strdup(path); name = get_prop_string(hal_ctx, udi, "info.product"); if (!name) - name = xstrdup("(unnamed)"); + name = strdup("(unnamed)"); else - attrs.product = xstrdup(name); + attrs.product = strdup(name); attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor"); hal_tags = get_prop_string(hal_ctx, udi, "input.tags"); @@ -211,8 +211,8 @@ device_added(LibHalContext *hal_ctx, const char *udi) goto unwind; } - options->key = xstrdup("_source"); - options->value = xstrdup("server/hal"); + options->key = strdup("_source"); + options->value = strdup("server/hal"); if (!options->key || !options->value) { LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n"); goto unwind; @@ -387,7 +387,7 @@ device_added(LibHalContext *hal_ctx, const char *udi) for (; dev; dev = dev->next){ free(dev->config_info); - dev->config_info = xstrdup(config_info); + dev->config_info = strdup(config_info); } unwind: diff --git a/config/udev.c b/config/udev.c index 16c4624557..993449075c 100644 --- a/config/udev.c +++ b/config/udev.c @@ -86,8 +86,8 @@ device_added(struct udev_device *udev_device) if (!options) return; - options->key = xstrdup("_source"); - options->value = xstrdup("server/udev"); + options->key = strdup("_source"); + options->value = strdup("server/udev"); if (!options->key || !options->value) goto unwind; @@ -197,7 +197,7 @@ device_added(struct udev_device *udev_device) for (; dev; dev = dev->next) { free(dev->config_info); - dev->config_info = xstrdup(config_info); + dev->config_info = strdup(config_info); } unwind: diff --git a/dix/dixfonts.c b/dix/dixfonts.c index 6c90fb9d20..b51ad841f2 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -1836,7 +1836,7 @@ SetDefaultFontPath(char *path) if (!start) { temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : ""); } else { - temp_path = xstrdup(path); + temp_path = strdup(path); } if (!temp_path) return BadAlloc; diff --git a/glx/glxcmds.c b/glx/glxcmds.c index 1d3be49213..9e5b2139e9 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -2433,7 +2433,7 @@ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc) cl->GLClientminorVersion = req->minor; free(cl->GLClientextensions); buf = (const char *)(req+1); - cl->GLClientextensions = xstrdup(buf); + cl->GLClientextensions = strdup(buf); return Success; } diff --git a/glx/glxscreens.c b/glx/glxscreens.c index a5b61df9fe..8515e14d55 100644 --- a/glx/glxscreens.c +++ b/glx/glxscreens.c @@ -356,9 +356,9 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen) return; pGlxScreen->pScreen = pScreen; - pGlxScreen->GLextensions = xstrdup(GLServerExtensions); - pGlxScreen->GLXvendor = xstrdup(GLXServerVendorName); - pGlxScreen->GLXextensions = xstrdup(GLXServerExtensions); + pGlxScreen->GLextensions = strdup(GLServerExtensions); + pGlxScreen->GLXvendor = strdup(GLXServerVendorName); + pGlxScreen->GLXextensions = strdup(GLXServerExtensions); /* All GLX providers must support all of the functionality required for at * least GLX 1.2. If the provider supports a higher version, the GLXminor diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c index 72dd546d4d..3344e50886 100644 --- a/xkb/xkbUtils.c +++ b/xkb/xkbUtils.c @@ -1761,15 +1761,15 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst) if (sdoodad->any.type == XkbTextDoodad) { if (sdoodad->text.text) ddoodad->text.text = - xstrdup(sdoodad->text.text); + strdup(sdoodad->text.text); if (sdoodad->text.font) ddoodad->text.font = - xstrdup(sdoodad->text.font); + strdup(sdoodad->text.font); } else if (sdoodad->any.type == XkbLogoDoodad) { if (sdoodad->logo.logo_name) ddoodad->logo.logo_name = - xstrdup(sdoodad->logo.logo_name); + strdup(sdoodad->logo.logo_name); } } dsection->overlays = NULL; @@ -1832,14 +1832,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst) memcpy(ddoodad , sdoodad, sizeof(XkbDoodadRec)); if (sdoodad->any.type == XkbTextDoodad) { if (sdoodad->text.text) - ddoodad->text.text = xstrdup(sdoodad->text.text); + ddoodad->text.text = strdup(sdoodad->text.text); if (sdoodad->text.font) - ddoodad->text.font = xstrdup(sdoodad->text.font); + ddoodad->text.font = strdup(sdoodad->text.font); } else if (sdoodad->any.type == XkbLogoDoodad) { if (sdoodad->logo.logo_name) ddoodad->logo.logo_name = - xstrdup(sdoodad->logo.logo_name); + strdup(sdoodad->logo.logo_name); } } From 16158366954d945db6263f6de505fc02ee03c6cd Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:00:15 +0700 Subject: [PATCH 02/10] dmx: Get rid of xstrdup when argument is definitely non-NULL ditto for DMX Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- hw/dmx/input/dmxinputinit.c | 4 ++-- hw/dmx/input/usb-keyboard.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/dmx/input/dmxinputinit.c b/hw/dmx/input/dmxinputinit.c index b2e16fba4a..83a2abbb82 100644 --- a/hw/dmx/input/dmxinputinit.c +++ b/hw/dmx/input/dmxinputinit.c @@ -885,7 +885,7 @@ static void dmxInputScanForExtensions(DMXInputInfo *dmxInput, int doXI) && dmxL->deviceId < 0) { dmxL->deviceId = devices[i].id; dmxL->deviceName = (devices[i].name - ? xstrdup(devices[i].name) + ? strdup(devices[i].name) : NULL); } } @@ -918,7 +918,7 @@ static void dmxInputScanForExtensions(DMXInputInfo *dmxInput, int doXI) dmxLocal->sendsCore = FALSE; dmxLocal->deviceId = devices[i].id; dmxLocal->deviceName = (devices[i].name - ? xstrdup(devices[i].name) + ? strdup(devices[i].name) : NULL); } } diff --git a/hw/dmx/input/usb-keyboard.c b/hw/dmx/input/usb-keyboard.c index dc575fef70..9db1adbfc6 100644 --- a/hw/dmx/input/usb-keyboard.c +++ b/hw/dmx/input/usb-keyboard.c @@ -439,6 +439,6 @@ void kbdUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) kbdUSBGetMap(pDev, &info->keySyms, info->modMap); info->focusClass = 1; info->kbdFeedbackClass = 1; - info->names.keycodes = xstrdup("powerpcps2"); + info->names.keycodes = strdup("powerpcps2"); info->force = 1; } From dd45b7d74696cd4fe9545852640a3c2e66a808fd Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:00:46 +0700 Subject: [PATCH 03/10] kdrive: Get rid of xstrdup when argument is definitely non-NULL ditto for Kdrive Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- hw/kdrive/src/kinput.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index 4024758849..80a1458b15 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -919,7 +919,7 @@ KdAddConfigKeyboard (char *keyboard) if (!new) return BadAlloc; - new->line = xstrdup(keyboard); + new->line = strdup(keyboard); new->next = NULL; for (prev = &kdConfigKeyboards; *prev; prev = &(*prev)->next); @@ -987,7 +987,7 @@ KdAddConfigPointer (char *pointer) if (!new) return BadAlloc; - new->line = xstrdup(pointer); + new->line = strdup(pointer); new->next = NULL; for (prev = &kdConfigPointers; *prev; prev = &(*prev)->next); @@ -1067,11 +1067,11 @@ KdGetOptions (InputOption **options, char *string) newopt->key = (char *)malloc(tam_key); strncpy(newopt->key, string, tam_key); newopt->key[tam_key] = '\0'; - newopt->value = xstrdup(strchr(string, '=') + 1); + newopt->value = strdup(strchr(string, '=') + 1); } else { - newopt->key = xstrdup(string); + newopt->key = strdup(string); newopt->value = NULL; } newopt->next = NULL; @@ -1147,7 +1147,7 @@ KdParseKeyboard (char *arg) if (strcmp (save, "auto") == 0) ki->driverPrivate = NULL; else - ki->driverPrivate = xstrdup(save); + ki->driverPrivate = strdup(save); if (delim != ',') { @@ -1243,7 +1243,7 @@ KdParsePointer (char *arg) if (strcmp(save, "auto") == 0) pi->driverPrivate = NULL; else - pi->driverPrivate = xstrdup(save); + pi->driverPrivate = strdup(save); if (delim != ',') { From eea286f2b9e4b1acf2b1c9800f5a4bc7c3fa968d Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:01:05 +0700 Subject: [PATCH 04/10] xwin: Get rid of xstrdup when argument is definitely non-NULL ditto for XWin Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- hw/xwin/InitOutput.c | 6 +++--- hw/xwin/glx/indirect.c | 6 +++--- hw/xwin/winconfig.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index 1ab059f72c..1b976061cf 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -441,7 +441,7 @@ winFixupPaths (void) int comment_block = FALSE; /* get defautl fontpath */ - char *fontpath = xstrdup(defaultFontPath); + char *fontpath = strdup(defaultFontPath); size_t size = strlen(fontpath); /* read all lines */ @@ -528,7 +528,7 @@ winFixupPaths (void) /* cleanup */ fclose(fontdirs); - defaultFontPath = xstrdup(fontpath); + defaultFontPath = strdup(fontpath); free(fontpath); changed_fontpath = TRUE; font_from = X_CONFIG; @@ -600,7 +600,7 @@ winFixupPaths (void) } } - defaultFontPath = xstrdup(newfp); + defaultFontPath = strdup(newfp); free(newfp); changed_fontpath = TRUE; } diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c index 5e0e917bc7..8ec40da33e 100755 --- a/hw/xwin/glx/indirect.c +++ b/hw/xwin/glx/indirect.c @@ -676,7 +676,7 @@ glxWinScreenProbe(ScreenPtr pScreen) fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs); // Override the GL extensions string set by __glXScreenInit() - screen->base.GLextensions = xstrdup(gl_extensions); + screen->base.GLextensions = strdup(gl_extensions); // Generate the GLX extensions string (overrides that set by __glXScreenInit()) { @@ -706,13 +706,13 @@ glxWinScreenProbe(ScreenPtr pScreen) if (screen->has_WGL_ARB_multisample) { - screen->base.GLXversion = xstrdup("1.4"); + screen->base.GLXversion = strdup("1.4"); screen->base.GLXmajor = 1; screen->base.GLXminor = 4; } else { - screen->base.GLXversion = xstrdup("1.3"); + screen->base.GLXversion = strdup("1.3"); screen->base.GLXmajor = 1; screen->base.GLXminor = 3; } diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index ab49aaa7a1..a88b6f1cf1 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -583,7 +583,7 @@ winConfigFiles () else if (filesptr != NULL && filesptr->file_fontpath) { from = X_CONFIG; - defaultFontPath = xstrdup (filesptr->file_fontpath); + defaultFontPath = strdup (filesptr->file_fontpath); } winMsg (from, "FontPath set to \"%s\"\n", defaultFontPath); @@ -630,7 +630,7 @@ winSetStrOption (pointer optlist, const char *name, char *deflt) if (ParseOptionValue (-1, optlist, &o)) deflt = o.value.str; if (deflt) - return xstrdup (deflt); + return strdup (deflt); else return NULL; } From 416d228481d71204cf9bfad3ab4773abc4757f79 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:01:25 +0700 Subject: [PATCH 05/10] xquartz: Get rid of xstrdup when argument is definitely non-NULL ditto for XQuartz Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- hw/xquartz/GL/indirect.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/xquartz/GL/indirect.c b/hw/xquartz/GL/indirect.c index f769ff2eca..3e8d730f2f 100644 --- a/hw/xquartz/GL/indirect.c +++ b/hw/xquartz/GL/indirect.c @@ -595,12 +595,12 @@ static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) { __glXScreenInit(&screen->base, pScreen); - screen->base.GLXversion = xstrdup("1.4"); - screen->base.GLXextensions = xstrdup("GLX_SGIX_fbconfig " - "GLX_SGIS_multisample " - "GLX_ARB_multisample " - "GLX_EXT_visual_info " - "GLX_EXT_import_context "); + screen->base.GLXversion = strdup("1.4"); + screen->base.GLXextensions = strdup("GLX_SGIX_fbconfig " + "GLX_SGIS_multisample " + "GLX_ARB_multisample " + "GLX_EXT_visual_info " + "GLX_EXT_import_context "); /*We may be able to add more GLXextensions at a later time. */ From e4570f5db5157f4233454c938733a2a0d6a1cb8f Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:01:42 +0700 Subject: [PATCH 06/10] xfree86: Get rid of xstrdup when argument is definitely non-NULL ditto for XFree86 Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- hw/xfree86/common/xf86Configure.c | 20 ++++++++++---------- hw/xfree86/common/xf86Option.c | 2 +- hw/xfree86/loader/loadmod.c | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 2f93bb13ba..822d767374 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -277,16 +277,16 @@ configureInputSection (void) mouse->inp_identifier = "Mouse0"; mouse->inp_driver = "mouse"; mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xstrdup("Protocol"), - xstrdup(DFLT_MOUSE_PROTO)); + xf86addNewOption(mouse->inp_option_lst, strdup("Protocol"), + strdup(DFLT_MOUSE_PROTO)); #ifndef __SCO__ mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xstrdup("Device"), - xstrdup(DFLT_MOUSE_DEV)); + xf86addNewOption(mouse->inp_option_lst, strdup("Device"), + strdup(DFLT_MOUSE_DEV)); #endif mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xstrdup("ZAxisMapping"), - xstrdup("4 5 6 7")); + xf86addNewOption(mouse->inp_option_lst, strdup("ZAxisMapping"), + strdup("4 5 6 7")); ptr = (XF86ConfInputPtr)xf86addListItem((glp)ptr, (glp)mouse); return ptr; } @@ -389,7 +389,7 @@ configureDeviceSection (int screennum) " ### : \"String\", : \" Hz/kHz/MHz\",\n" " ### : \"%\"\n" " ### [arg]: arg optional\n"; - ptr->dev_comment = xstrdup(descrip); + ptr->dev_comment = strdup(descrip); if (ptr->dev_comment) { for (p = DevToConfig[screennum].GDev.options; p->name != NULL; p++) { @@ -440,7 +440,7 @@ configureLayoutSection (void) iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = "Mouse0"; iptr->iref_option_lst = - xf86addNewOption (iptr->iref_option_lst, xstrdup("CorePointer"), NULL); + xf86addNewOption (iptr->iref_option_lst, strdup("CorePointer"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); } @@ -453,7 +453,7 @@ configureLayoutSection (void) iptr->iref_option_lst = NULL; iptr->iref_inputdev_str = "Keyboard0"; iptr->iref_option_lst = - xf86addNewOption (iptr->iref_option_lst, xstrdup("CoreKeyboard"), NULL); + xf86addNewOption (iptr->iref_option_lst, strdup("CoreKeyboard"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr); } @@ -626,7 +626,7 @@ configureDDCMonitorSection (int screennum) ptr); if (ConfiguredMonitor->features.dpms) { - ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, xstrdup("DPMS"), NULL); + ptr->mon_option_lst = xf86addNewOption(ptr->mon_option_lst, strdup("DPMS"), NULL); } return ptr; diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index 91a67186fa..aa6ea30117 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -209,7 +209,7 @@ LookupStrOption(pointer optlist, const char *name, char *deflt, Bool markUsed) if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.str; if (deflt) - return xstrdup(deflt); + return strdup(deflt); else return NULL; } diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index 4962443120..615e8c691d 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -135,7 +135,7 @@ InitPathList(const char *path) if (!path) return defaultPathList; - fullpath = xstrdup(path); + fullpath = strdup(path); if (!fullpath) return NULL; elem = strtok(fullpath, ","); @@ -353,7 +353,7 @@ InitSubdirs(const char **subdirlist) sprintf(subdirs[i], "%s%s%s/", *s, slash, osname); i++; /* path as given */ - subdirs[i] = xstrdup(*s); + subdirs[i] = strdup(*s); i++; s++; if (indefault && !s) { @@ -1246,7 +1246,7 @@ LoaderGetCanonicalName(const char *modname, PatternPtr patterns) } /* If there is no match, return the whole name minus the leading path */ - return xstrdup(s); + return strdup(s); } /* From 6e7417c342b0624e3f3c5686bb43026786423692 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 4 Jun 2010 17:05:35 +0700 Subject: [PATCH 07/10] config: Replace xstrdup with strdup in add_option() All callers of add_option pass string literal as "key" argument except one, where non-NULL condition is guarded by if(). Signed-off-by: Mikhail Gusarov Reviewed-by: Alan Coopersmith --- config/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.c b/config/config.c index d42a16a1fd..d86f7c6491 100644 --- a/config/config.c +++ b/config/config.c @@ -133,7 +133,7 @@ add_option(InputOption **options, const char *key, const char *value) *options = calloc(sizeof(**options), 1); if (!*options) /* Yeesh. */ return; - (*options)->key = xstrdup(key); + (*options)->key = strdup(key); (*options)->value = strdup(value); (*options)->next = NULL; } From a54a766dfb39fb3df671045878ac706215d83cef Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Mon, 7 Jun 2010 03:19:03 +0700 Subject: [PATCH 08/10] xkb: replace xstrdup with strdup in Win32System The only caller of Win32System is XkbDDXCompileKeymapByNames. Add allocation check there to avoid passing NULL pointers to various functions down the code. Signed-off-by: Mikhail Gusarov Reviewed-by: Peter Hutterer --- xkb/ddxLoad.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index b1d6294365..5e6ab8770b 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -103,7 +103,7 @@ Win32System(const char *cmdline) STARTUPINFO si; PROCESS_INFORMATION pi; DWORD dwExitCode; - char *cmd = xstrdup(cmdline); + char *cmd = strdup(cmdline); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); @@ -235,6 +235,11 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, xkm_output_dir, keymap); free(xkbbasedirflag); + + if (!buf) { + LogMessage(X_ERROR, "XKB: Could not invoke xkbcomp: not enough memory\n"); + return FALSE; + } #ifndef WIN32 out= Popen(buf,"w"); From 89bd05106e5823fc5cfca9abf082729f2444363b Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 4 Jun 2010 21:09:35 -0400 Subject: [PATCH 09/10] record: move free() to after last use of pContext No functional change, since free doesn't change the value of the pointer passed to it, but it makes this code less confusing. Reviewed-by: Jamey Sharp Signed-off-by: Matt Turner --- record/record.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/record/record.c b/record/record.c index 53bdfec714..4117a5a025 100644 --- a/record/record.c +++ b/record/record.c @@ -2520,8 +2520,6 @@ RecordDeleteContext(pointer value, XID id) } } - free(pContext); - /* remove context from AllContexts list */ if (-1 != (i = RecordFindContextOnAllContexts(pContext))) @@ -2533,6 +2531,8 @@ RecordDeleteContext(pointer value, XID id) ppAllContexts = NULL; } } + free(pContext); + return Success; } /* RecordDeleteContext */ From f4190feb25ecc3d8278decc8bf28a5ef0e568942 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Thu, 10 Jun 2010 04:08:54 +0700 Subject: [PATCH 10/10] Remove more superfluous if(p) checks around free(p) Reviewed-by: Alan Coopersmith Signed-off-by: Matt Turner Signed-off-by: Mikhail Gusarov --- exa/exa_glyphs.c | 12 ++++-------- hw/kdrive/ephyr/ephyrhostvideo.c | 6 ++---- hw/kdrive/ephyr/hostx.c | 25 ++++++++----------------- hw/xfree86/modes/xf86Cursors.c | 7 ++----- hw/xfree86/os-support/bus/Sbus.c | 6 ++---- hw/xwin/InitOutput.c | 7 ++----- xkb/XKBGAlloc.c | 18 ++++++------------ xkb/XKBMAlloc.c | 18 ++++++------------ xkb/ddxList.c | 5 +---- xkb/xkb.c | 21 ++++++++++++--------- xkb/xkbInit.c | 6 ++---- 11 files changed, 47 insertions(+), 84 deletions(-) diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c index b09db46b0f..5c46ec9013 100644 --- a/exa/exa_glyphs.c +++ b/exa/exa_glyphs.c @@ -127,15 +127,11 @@ exaUnrealizeGlyphCaches(ScreenPtr pScreen, cache->picture = NULL; } - if (cache->hashEntries) { - free(cache->hashEntries); - cache->hashEntries = NULL; - } + free(cache->hashEntries); + cache->hashEntries = NULL; - if (cache->glyphs) { - free(cache->glyphs); - cache->glyphs = NULL; - } + free(cache->glyphs); + cache->glyphs = NULL; cache->glyphCount = 0; } } diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c index 38927b02d7..9dde768c85 100644 --- a/hw/kdrive/ephyr/ephyrhostvideo.c +++ b/hw/kdrive/ephyr/ephyrhostvideo.c @@ -831,10 +831,8 @@ out: XFreeGC (dpy, gc) ; gc = NULL ; } - if (rects) { - free (rects) ; - rects = NULL ; - } + free(rects); + rects = NULL; EPHYR_LOG ("leave\n") ; return is_ok ; } diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c index 38ee06d252..2ebeca9589 100644 --- a/hw/kdrive/ephyr/hostx.c +++ b/hw/kdrive/ephyr/hostx.c @@ -669,11 +669,8 @@ hostx_screen_init (EphyrScreenInfo screen, } else { - if (host_screen->ximg->data) - { - free(host_screen->ximg->data); - host_screen->ximg->data = NULL; - } + free(host_screen->ximg->data); + host_screen->ximg->data = NULL; XDestroyImage(host_screen->ximg); } @@ -1160,10 +1157,8 @@ out: XFree (visuals) ; visuals = NULL; } - if (host_visuals) { - free (host_visuals) ; - host_visuals = NULL; - } + free(host_visuals); + host_visuals = NULL; EPHYR_LOG ("leave\n") ; return is_ok ; @@ -1292,10 +1287,8 @@ hostx_set_window_bounding_rectangles (int a_window, rects, a_num_rects, ShapeSet, YXBanded) ; is_ok = TRUE ; - if (rects) { - free (rects) ; - rects = NULL ; - } + free(rects); + rects = NULL; EPHYR_LOG ("leave\n") ; return is_ok; } @@ -1329,10 +1322,8 @@ hostx_set_window_clipping_rectangles (int a_window, rects, a_num_rects, ShapeSet, YXBanded) ; is_ok = TRUE ; - if (rects) { - free (rects) ; - rects = NULL ; - } + free(rects); + rects = NULL; EPHYR_LOG ("leave\n") ; return is_ok; } diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c index 5842a613c0..038f1c89cd 100644 --- a/hw/xfree86/modes/xf86Cursors.c +++ b/hw/xfree86/modes/xf86Cursors.c @@ -659,11 +659,8 @@ xf86_cursors_fini (ScreenPtr screen) xf86DestroyCursorInfoRec (xf86_config->cursor_info); xf86_config->cursor_info = NULL; } - if (xf86_config->cursor_image) - { - free(xf86_config->cursor_image); - xf86_config->cursor_image = NULL; - } + free(xf86_config->cursor_image); + xf86_config->cursor_image = NULL; if (xf86_config->cursor) { FreeCursor (xf86_config->cursor, None); diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c index 9ccc2898f6..7829d803f2 100644 --- a/hw/xfree86/os-support/bus/Sbus.c +++ b/hw/xfree86/os-support/bus/Sbus.c @@ -191,10 +191,8 @@ sparcPromClose(void) close(promFd); promFd = -1; } - if (promOpio) { - free(promOpio); - promOpio = NULL; - } + free(promOpio); + promOpio = NULL; promOpenCount = 0; } diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index 1b976061cf..73cc263bdd 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -275,11 +275,8 @@ ddxGiveUp (void) } /* Free concatenated command line */ - if (g_pszCommandLine) - { - free (g_pszCommandLine); - g_pszCommandLine = NULL; - } + free(g_pszCommandLine); + g_pszCommandLine = NULL; /* Remove our keyboard hook if it is installed */ winRemoveKeyboardHookLL (); diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c index 796931cf48..d1adea34e1 100644 --- a/xkb/XKBGAlloc.c +++ b/xkb/XKBGAlloc.c @@ -114,10 +114,8 @@ register char *ptr; } if (freeAll) { (*num_inout)= (*sz_inout)= 0; - if (*elems) { - free(*elems); - *elems= NULL; - } + free(*elems); + *elems = NULL; } else if (first+count>=(*num_inout)) *num_inout= first; @@ -137,14 +135,10 @@ _XkbClearProperty(char *prop_in) { XkbPropertyPtr prop= (XkbPropertyPtr)prop_in; - if (prop->name) { - free(prop->name); - prop->name= NULL; - } - if (prop->value) { - free(prop->value); - prop->value= NULL; - } + free(prop->name); + prop->name = NULL; + free(prop->value); + prop->value = NULL; return; } diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c index 197523f573..6b186c1adc 100644 --- a/xkb/XKBMAlloc.c +++ b/xkb/XKBMAlloc.c @@ -221,18 +221,12 @@ XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into) { if ((!from)||(!into)) return BadMatch; - if (into->map) { - free(into->map); - into->map= NULL; - } - if (into->preserve) { - free(into->preserve); - into->preserve= NULL; - } - if (into->level_names) { - free(into->level_names); - into->level_names= NULL; - } + free(into->map); + into->map = NULL; + free(into->preserve); + into->preserve = NULL; + free(into->level_names); + into->level_names = NULL; *into= *from; if ((from->map)&&(into->map_count>0)) { into->map= calloc(into->map_count, sizeof(XkbKTMapEntryRec)); diff --git a/xkb/ddxList.c b/xkb/ddxList.c index eee3887491..2256424d0e 100644 --- a/xkb/ddxList.c +++ b/xkb/ddxList.c @@ -208,10 +208,7 @@ char tmpname[PATH_MAX]; return BadImplementation; } list->nFound[what]= 0; - if (buf) { - free(buf); - buf = NULL; - } + free(buf); buf = malloc(PATH_MAX * sizeof(char)); if (!buf) return BadAlloc; diff --git a/xkb/xkb.c b/xkb/xkb.c index cbb46c62fd..bd73e9a8e1 100644 --- a/xkb/xkb.c +++ b/xkb/xkb.c @@ -5510,10 +5510,8 @@ ProcXkbListComponents(ClientPtr client) if ((XkbPaddedSize(len)/4)!=stuff->length) return BadLength; if ((status=XkbDDXList(dev,&list,client))!=Success) { - if (list.pool) { - free(list.pool); - list.pool= NULL; - } + free(list.pool); + list.pool = NULL; return status; } memset(&rep, 0, sizeof(xkbListComponentsReply)); @@ -5886,11 +5884,16 @@ ProcXkbGetKbdByName(ClientPtr client) XkbFreeKeyboard(new,XkbAllComponentsMask,TRUE); new= NULL; } - if (names.keycodes) { free(names.keycodes); names.keycodes= NULL; } - if (names.types) { free(names.types); names.types= NULL; } - if (names.compat) { free(names.compat); names.compat= NULL; } - if (names.symbols) { free(names.symbols); names.symbols= NULL; } - if (names.geometry) { free(names.geometry); names.geometry= NULL; } + free(names.keycodes); + names.keycodes = NULL; + free(names.types); + names.types = NULL; + free(names.compat); + names.compat = NULL; + free(names.symbols); + names.symbols = NULL; + free(names.geometry); + names.geometry = NULL; return Success; } diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c index bd58243cae..fbf8f14b84 100644 --- a/xkb/xkbInit.c +++ b/xkb/xkbInit.c @@ -635,10 +635,8 @@ unwind_key: void XkbFreeInfo(XkbSrvInfoPtr xkbi) { - if (xkbi->radioGroups) { - free(xkbi->radioGroups); - xkbi->radioGroups= NULL; - } + free(xkbi->radioGroups); + xkbi->radioGroups = NULL; if (xkbi->mouseKeyTimer) { TimerFree(xkbi->mouseKeyTimer); xkbi->mouseKeyTimer= NULL;