Fix bad behaviour on realloc resulting in crash.

reviewed by: plam
This commit is contained in:
Patrick Lam 2006-04-12 03:02:57 +00:00
parent 5c90509c07
commit a56e89ab4f
2 changed files with 17 additions and 7 deletions

View File

@ -1,3 +1,10 @@
2006-04-11 Ming Zhao <ming@gentoo.org>
reviewed by: plam
* src/fcname.c (FcObjectToPtrLookup):
Fix bad behaviour on realloc resulting in crash.
2006-04-11 Patrick Lam <plam@mit.edu> 2006-04-11 Patrick Lam <plam@mit.edu>
* src/fccache.c (FcGlobalCacheReadDir): * src/fccache.c (FcGlobalCacheReadDir):

View File

@ -193,7 +193,8 @@ FcObjectToPtrLookup (const char * object)
{ {
FcObjectPtr i = 0, n; FcObjectPtr i = 0, n;
const FcObjectTypeList *l; const FcObjectTypeList *l;
FcObjectType *t = _FcUserObjectNames; FcObjectType *t = _FcUserObjectNames, *origNames;
FcBool replace;
for (l = _FcObjectTypes; l; l = l->next) for (l = _FcObjectTypes; l; l = l->next)
{ {
@ -212,25 +213,27 @@ FcObjectToPtrLookup (const char * object)
/* We didn't match. Look for the application's FcObjectTypeList /* We didn't match. Look for the application's FcObjectTypeList
* and replace it in-place. */ * and replace it in-place. */
origNames = _FcUserObjectNames;
for (l = _FcObjectTypes; l; l = l->next) for (l = _FcObjectTypes; l; l = l->next)
{ {
if (l->types == _FcUserObjectNames) if (l->types == _FcUserObjectNames)
break; break;
} }
replace = l && l->types == _FcUserObjectNames;
if (!_FcUserObjectNames || if (!_FcUserObjectNames ||
(l && l->types == _FcUserObjectNames && user_obj_alloc < l->ntypes)) (replace && user_obj_alloc <= l->ntypes))
{ {
int nt = user_obj_alloc + 4; int nt = user_obj_alloc + 4;
FcObjectType * t = realloc (_FcUserObjectNames, FcObjectType * tt = realloc (_FcUserObjectNames,
nt * sizeof (FcObjectType)); nt * sizeof (FcObjectType));
if (!t) if (!tt)
return 0; return 0;
_FcUserObjectNames = t; _FcUserObjectNames = tt;
user_obj_alloc = nt; user_obj_alloc = nt;
} }
if (l && l->types == _FcUserObjectNames) if (replace)
{ {
n = l->ntypes; n = l->ntypes;
FcNameUnregisterObjectTypesFree (l->types, l->ntypes, FcFalse); FcNameUnregisterObjectTypesFree (l->types, l->ntypes, FcFalse);
@ -242,7 +245,7 @@ FcObjectToPtrLookup (const char * object)
for (l = _FcObjectTypes; l; l = l->next) for (l = _FcObjectTypes; l; l = l->next)
{ {
if (l->types == _FcUserObjectNames) if (l->types == origNames)
{ {
t = (FcObjectType *)l->types; t = (FcObjectType *)l->types;
break; break;