From 747bf5fe80f51554205c5a50b8ed9b89065c8a54 Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Sun, 1 Aug 2010 16:01:23 -0700 Subject: [PATCH 1/7] xfree86: Remove comments about unable to use malloc. These are leftovers from when X still used Xmalloc and friends for allocation. Now that those are gone, these comments are just confusing. Signed-off-by: Jesse Adkins Reviewed-by: Peter Hutterer Signed-off-by: Matt Turner --- hw/xfree86/common/xf86Init.c | 5 ----- hw/xfree86/parser/Flags.c | 2 -- 2 files changed, 7 deletions(-) diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index ca532ee81..560519daf 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -1046,11 +1046,6 @@ xf86PrintDefaultLibraryPath(void) int ddxProcessArgument(int argc, char **argv, int i) { - /* - * Note: can't use xalloc/xfree here because OsInit() hasn't been called - * yet. Use malloc/free instead. - */ - #define CHECK_FOR_REQUIRED_ARGUMENT() \ if (((i + 1) >= argc) || (!argv[i + 1])) { \ ErrorF("Required argument to %s not specified\n", argv[i]); \ diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c index 699dc6bcb..7fafb6ca8 100644 --- a/hw/xfree86/parser/Flags.c +++ b/hw/xfree86/parser/Flags.c @@ -132,7 +132,6 @@ xf86parseFlagsSection (void) if (ServerFlagsTab[i].token == token) { char *valstr = NULL; - /* can't use strdup because it calls malloc */ tmp = strdup (ServerFlagsTab[i].name); if (hasvalue) { @@ -365,7 +364,6 @@ xf86optionListCreate( const char **options, int count, int used ) } for (i = 0; i < count; i += 2) { - /* can't use strdup because it calls malloc */ t1 = malloc (sizeof (char) * (strlen (options[i]) + 1)); strcpy (t1, options[i]); From f49473abfd6034e68576b2dddd30ba8d8dd0838f Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Wed, 4 Aug 2010 09:21:29 +0000 Subject: [PATCH 2/7] xfree86: Remove prototypes for non-existant functions. This was obsolete from 9a0f25de7ca3c68af867b38936103d17daa92ac6 "Static cleanups, dead code deletion." (server 1.3). Signed-off-by: Jesse Adkins Signed-off-by: Matt Turner --- hw/xfree86/loader/loader.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h index ac5f99cf5..6121e02c6 100644 --- a/hw/xfree86/loader/loader.h +++ b/hw/xfree86/loader/loader.h @@ -88,15 +88,9 @@ extern const ModuleVersions LoaderVersionInfo; extern unsigned long LoaderOptions; /* Internal Functions */ -void LoaderDuplicateSymbol(const char *, const int); -char *_LoaderModuleToName(int); int LoaderOpen(const char *, const char *, int, int *, int *, int *, int); int LoaderHandleOpen(int); -/* object to name lookup routines */ -char *_LoaderHandleToName(int handle); -char *_LoaderHandleToCanonicalName(int handle); - /* Loader backends. */ #include "dlloader.h" From 4f04fd595e82226f1d91226a41bb98ed3d940b37 Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Wed, 4 Aug 2010 09:21:30 +0000 Subject: [PATCH 3/7] xfree86: Simplify xf86Msg{,Verb} Previously, the functions would call xf86VDrvMsgVerb with a screen of -1 despite their comments saying they were for "non-driver messages". They now call LogVMessageVerb, which is what xf86VDrvMsgVerb does anyway when it has a screen == -1. Reviewed-by: Peter Hutterer Reviewed-by: Mark Kettenis Signed-off-by: Jesse Adkins Signed-off-by: Matt Turner --- hw/xfree86/common/xf86Helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 07f9f0a52..90e0c6702 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1267,7 +1267,7 @@ xf86MsgVerb(MessageType type, int verb, const char *format, ...) va_list ap; va_start(ap, format); - xf86VDrvMsgVerb(-1, type, verb, format, ap); + LogVMessageVerb(type, verb, format, ap); va_end(ap); } @@ -1278,7 +1278,7 @@ xf86Msg(MessageType type, const char *format, ...) va_list ap; va_start(ap, format); - xf86VDrvMsgVerb(-1, type, 1, format, ap); + LogVMessageVerb(type, 1, format, ap); va_end(ap); } From 18b62e0479f15e965611880ada6e0195367df025 Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Wed, 4 Aug 2010 09:21:31 +0000 Subject: [PATCH 4/7] xfree86: Fix leaks in OpenConfigFile and OpenConfigDir [mattst88: fixed whitespace and a missing semicolon] Signed-off-by: Jesse Adkins Signed-off-by: Matt Turner --- hw/xfree86/parser/scan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c index 531214350..4163a3a6b 100644 --- a/hw/xfree86/parser/scan.c +++ b/hw/xfree86/parser/scan.c @@ -819,6 +819,7 @@ OpenConfigFile(const char *path, const char *cmdline, const char *projroot, } } + free(pathcopy); if (file) { configFiles[numFiles].file = file; configFiles[numFiles].path = strdup(filepath); @@ -927,6 +928,7 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot, } } + free(pathcopy); return dirpath; } From b25fb9fe998209e79b6917d12d5765c5f6719a7e Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Wed, 4 Aug 2010 09:21:32 +0000 Subject: [PATCH 5/7] xfree86: Removed unused messages from Configint.h AUTOREPEAT_MSG, MOVED_TO_FLAGS_MSG, and XLEDS_MSG made obsolete by 81913a12910e39d7ea6af8657c1c66cc6791cd65 Jul 21 2006 (remove undead files from master) UNDEFINED_DEVICE_MSG made obsolete by 6033d8150be3a115b90226eaa42f237bb0cf3369 Oct 9 2007 (first pass at video driver autoloading) Signed-off-by: Jesse Adkins Signed-off-by: Matt Turner --- hw/xfree86/parser/Configint.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hw/xfree86/parser/Configint.h b/hw/xfree86/parser/Configint.h index dda020e68..c88ff46d7 100644 --- a/hw/xfree86/parser/Configint.h +++ b/hw/xfree86/parser/Configint.h @@ -152,10 +152,6 @@ else\ "The %s keyword requires a boolean to follow it." #define ZAXISMAPPING_MSG \ "The ZAxisMapping keyword requires 2 positive numbers or X or Y to follow it." -#define AUTOREPEAT_MSG \ -"The AutoRepeat keyword requires 2 numbers (delay and rate) to follow it." -#define XLEDS_MSG \ -"The XLeds keyword requries one or more numbers to follow it." #define DACSPEED_MSG \ "The DacSpeed keyword must be followed by a list of up to %d numbers." #define DISPLAYSIZE_MSG \ @@ -216,7 +212,5 @@ else\ /* Warning messages */ #define OBSOLETE_MSG \ "Ignoring obsolete keyword \"%s\"." -#define MOVED_TO_FLAGS_MSG \ -"Keyword \"%s\" is now an Option flag in the ServerFlags section." #endif /* _Configint_h_ */ From ea239112b030588ed3cdd113643ba5f6207a5bd9 Mon Sep 17 00:00:00 2001 From: Jesse Adkins Date: Wed, 4 Aug 2010 09:21:33 +0000 Subject: [PATCH 6/7] xfree86: Purge parsePrologueVoid. This was included in the original commit, and then never used. Signed-off-by: Jesse Adkins Signed-off-by: Matt Turner --- hw/xfree86/parser/Configint.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/xfree86/parser/Configint.h b/hw/xfree86/parser/Configint.h index c88ff46d7..82d7de4c4 100644 --- a/hw/xfree86/parser/Configint.h +++ b/hw/xfree86/parser/Configint.h @@ -98,9 +98,6 @@ LexRec, *LexPtr; #define parsePrologue(typeptr,typerec) typeptr ptr; \ if( (ptr=calloc(1,sizeof(typerec))) == NULL ) { return NULL; } -#define parsePrologueVoid(typeptr,typerec) int token; typeptr ptr; \ -if( (ptr=calloc(1,sizeof(typerec))) == NULL ) { return; } - #define HANDLE_RETURN(f,func)\ if ((ptr->f=func) == NULL)\ {\ From 08adf41f6315663cbac33d010214d98f3e1c8814 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 27 Aug 2010 18:34:49 -0400 Subject: [PATCH 7/7] Replace malloc/strlen/strcpy with strdup. Reviewed-by: Jeremy Huddleston Signed-off-by: Matt Turner --- Xi/extinit.c | 3 +-- dix/extension.c | 6 ++---- hw/kdrive/src/kxv.c | 9 +++------ hw/xfree86/common/xf86Init.c | 6 ++---- hw/xfree86/common/xf86xv.c | 9 +++------ hw/xfree86/loader/loader.c | 6 ++---- hw/xfree86/parser/Flags.c | 8 ++------ hw/xfree86/parser/scan.c | 3 +-- hw/xquartz/mach-startup/bundle-main.c | 3 +-- hw/xwin/glx/indirect.c | 5 +---- 10 files changed, 18 insertions(+), 40 deletions(-) diff --git a/Xi/extinit.c b/Xi/extinit.c index eda4efb50..7edadeaf2 100644 --- a/Xi/extinit.c +++ b/Xi/extinit.c @@ -1154,8 +1154,7 @@ void AssignTypeAndName(DeviceIntPtr dev, Atom type, char *name) { dev->xinput_type = type; - dev->name = (char *)malloc(strlen(name) + 1); - strcpy(dev->name, name); + dev->name = strdup(name); } /*********************************************************************** diff --git a/dix/extension.c b/dix/extension.c index c8e921a19..6540b64b0 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -96,7 +96,7 @@ AddExtension(char *name, int NumEvents, int NumErrors, free(ext); return NULL; } - ext->name = malloc(strlen(name) + 1); + ext->name = strdup(name); ext->num_aliases = 0; ext->aliases = (char **)NULL; if (!ext->name) @@ -105,7 +105,6 @@ AddExtension(char *name, int NumEvents, int NumErrors, free(ext); return((ExtensionEntry *) NULL); } - strcpy(ext->name, name); i = NumExtensions; newexts = (ExtensionEntry **) realloc(extensions, (i + 1) * sizeof(ExtensionEntry *)); @@ -164,10 +163,9 @@ Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) if (!aliases) return FALSE; ext->aliases = aliases; - name = malloc(strlen(alias) + 1); + name = strdup(alias); if (!name) return FALSE; - strcpy(name, alias); ext->aliases[ext->num_aliases] = name; ext->num_aliases++; return TRUE; diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c index c07829a5f..50dc23529 100644 --- a/hw/kdrive/src/kxv.c +++ b/hw/kdrive/src/kxv.c @@ -377,8 +377,7 @@ KdXVInitAdaptors( pa->ddGetPortAttribute = KdXVGetPortAttribute; pa->ddQueryBestSize = KdXVQueryBestSize; pa->ddQueryImageAttributes = KdXVQueryImageAttributes; - if((pa->name = malloc(strlen(adaptorPtr->name) + 1))) - strcpy(pa->name, adaptorPtr->name); + pa->name = strdup(adaptorPtr->name); if(adaptorPtr->nEncodings && (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { @@ -388,8 +387,7 @@ KdXVInitAdaptors( { pe->id = encodingPtr->id; pe->pScreen = pScreen; - if((pe->name = malloc(strlen(encodingPtr->name) + 1))) - strcpy(pe->name, encodingPtr->name); + pe->name = strdup(encodingPtr->name); pe->width = encodingPtr->width; pe->height = encodingPtr->height; pe->rate.numerator = encodingPtr->rate.numerator; @@ -441,8 +439,7 @@ KdXVInitAdaptors( pat->flags = attributePtr->flags; pat->min_value = attributePtr->min_value; pat->max_value = attributePtr->max_value; - if((pat->name = malloc(strlen(attributePtr->name) + 1))) - strcpy(pat->name, attributePtr->name); + pat->name = strdup(attributePtr->name); } pa->nAttributes = adaptorPtr->nAttributes; pa->pAttributes = pAttribute; diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 560519daf..3c7fbcb64 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -1062,10 +1062,9 @@ ddxProcessArgument(int argc, char **argv, int i) { char *mp; CHECK_FOR_REQUIRED_ARGUMENT(); - mp = malloc(strlen(argv[i + 1]) + 1); + mp = strdup(argv[i + 1]); if (!mp) FatalError("Can't allocate memory for ModulePath\n"); - strcpy(mp, argv[i + 1]); xf86ModulePath = mp; xf86ModPathFrom = X_CMDLINE; return 2; @@ -1074,10 +1073,9 @@ ddxProcessArgument(int argc, char **argv, int i) { char *lf; CHECK_FOR_REQUIRED_ARGUMENT(); - lf = malloc(strlen(argv[i + 1]) + 1); + lf = strdup(argv[i + 1]); if (!lf) FatalError("Can't allocate memory for LogFile\n"); - strcpy(lf, argv[i + 1]); xf86LogFile = lf; xf86LogFileFrom = X_CMDLINE; return 2; diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c index c1d319976..46761303d 100644 --- a/hw/xfree86/common/xf86xv.c +++ b/hw/xfree86/common/xf86xv.c @@ -429,8 +429,7 @@ xf86XVInitAdaptors( pa->ddGetPortAttribute = xf86XVGetPortAttribute; pa->ddQueryBestSize = xf86XVQueryBestSize; pa->ddQueryImageAttributes = xf86XVQueryImageAttributes; - if((pa->name = malloc(strlen(adaptorPtr->name) + 1))) - strcpy(pa->name, adaptorPtr->name); + pa->name = strdup(adaptorPtr->name); if(adaptorPtr->nEncodings && (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { @@ -440,8 +439,7 @@ xf86XVInitAdaptors( { pe->id = encodingPtr->id; pe->pScreen = pScreen; - if((pe->name = malloc(strlen(encodingPtr->name) + 1))) - strcpy(pe->name, encodingPtr->name); + pe->name = strdup(encodingPtr->name); pe->width = encodingPtr->width; pe->height = encodingPtr->height; pe->rate.numerator = encodingPtr->rate.numerator; @@ -493,8 +491,7 @@ xf86XVInitAdaptors( pat->flags = attributePtr->flags; pat->min_value = attributePtr->min_value; pat->max_value = attributePtr->max_value; - if((pat->name = malloc(strlen(attributePtr->name) + 1))) - strcpy(pat->name, attributePtr->name); + pat->name = strdup(attributePtr->name); } pa->nAttributes = adaptorPtr->nAttributes; pa->pAttributes = pAttribute; diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c index 6a4c08916..e043bb233 100644 --- a/hw/xfree86/loader/loader.c +++ b/hw/xfree86/loader/loader.c @@ -212,10 +212,8 @@ LoaderOpen(const char *module, const char *cname, int handle, refCount[new_handle] = 1; tmp = _LoaderListPush(); - tmp->name = malloc(strlen(module) + 1); - strcpy(tmp->name, module); - tmp->cname = malloc(strlen(cname) + 1); - strcpy(tmp->cname, cname); + tmp->name = strdup(module); + tmp->cname = strdup(cname); tmp->handle = new_handle; tmp->module = moduleseq++; diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c index 7fafb6ca8..a9149c243 100644 --- a/hw/xfree86/parser/Flags.c +++ b/hw/xfree86/parser/Flags.c @@ -364,12 +364,8 @@ xf86optionListCreate( const char **options, int count, int used ) } for (i = 0; i < count; i += 2) { - t1 = malloc (sizeof (char) * - (strlen (options[i]) + 1)); - strcpy (t1, options[i]); - t2 = malloc (sizeof (char) * - (strlen (options[i + 1]) + 1)); - strcpy (t2, options[i + 1]); + t1 = strdup(options[i]); + t2 = strdup(options[i + 1]); p = addNewOption2 (p, t1, t2, used); } diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c index 4163a3a6b..e609bdfd5 100644 --- a/hw/xfree86/parser/scan.c +++ b/hw/xfree86/parser/scan.c @@ -1090,8 +1090,7 @@ void xf86setSection (char *section) { free(configSection); - configSection = malloc(strlen (section) + 1); - strcpy (configSection, section); + configSection = strdup(section); } /* diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c index 6f7bbfdc2..7ac5469eb 100644 --- a/hw/xquartz/mach-startup/bundle-main.c +++ b/hw/xquartz/mach-startup/bundle-main.c @@ -479,12 +479,11 @@ static void setup_env(void) { pds = LAUNCHD_ID_PREFIX".X11"; } - server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1)); + server_bootstrap_name = strdup(pds); if(!server_bootstrap_name) { fprintf(stderr, "X11.app: Memory allocation error.\n"); exit(1); } - strcpy(server_bootstrap_name, pds); setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1); len = strlen(server_bootstrap_name); diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c index 1cf82a7cc..38918859a 100755 --- a/hw/xwin/glx/indirect.c +++ b/hw/xwin/glx/indirect.c @@ -444,7 +444,7 @@ glxLogExtensions(const char *prefix, const char *extensions) { int length = 0; char *strl; - char *str = malloc(strlen(extensions) + 1); + char *str = strdup(extensions); if (str == NULL) { @@ -452,9 +452,6 @@ glxLogExtensions(const char *prefix, const char *extensions) return; } - str[strlen(extensions)] = '\0'; - strncpy (str, extensions, strlen(extensions)); - strl = strtok(str, " "); ErrorF("%s%s", prefix, strl); length = strlen(prefix) + strlen(strl);