fontconfig: Branch 'main'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 src/fcatomic.c  |    3 +-
 src/fccfg.c     |   75 +++++++++++++++++++++++++++++---------------------------
 src/fcfs.c      |   15 ++++++-----
 src/fclist.c    |   13 +++++----
 src/fcpat.c     |    8 ++---
 src/fcptrlist.c |   17 +++++++-----
 src/fcrange.c   |    3 +-
 src/fcstr.c     |   39 +++++++++++++++--------------
 8 files changed, 95 insertions(+), 78 deletions(-)

New commits:
commit ed6c9cf67b46ce467e17eaeca4738a864e2b2ca3
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Mon Dec 5 21:40:26 2022 +0900

    Ignore null pointer on Fc*Destroy functions
    
    Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/339

diff --git a/src/fcatomic.c b/src/fcatomic.c
index 5b5e030..be09457 100644
--- a/src/fcatomic.c
+++ b/src/fcatomic.c
@@ -229,7 +229,8 @@ FcAtomicUnlock (FcAtomic *atomic)
 void
 FcAtomicDestroy (FcAtomic *atomic)
 {
-    free (atomic);
+    if (atomic)
+	free (atomic);
 }
 #define __fcatomic__
 #include "fcaliastail.h"
diff --git a/src/fccfg.c b/src/fccfg.c
index eb174a4..29124f5 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -362,40 +362,43 @@ FcConfigDestroy (FcConfig *config)
     FcExprPage	*page;
     FcMatchKind	k;
 
-    if (FcRefDec (&config->ref) != 1)
-	return;
+    if (config)
+    {
+	if (FcRefDec (&config->ref) != 1)
+	    return;
 
-    (void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
+	(void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
 
-    FcStrSetDestroy (config->configDirs);
-    FcStrSetDestroy (config->configMapDirs);
-    FcStrSetDestroy (config->fontDirs);
-    FcStrSetDestroy (config->cacheDirs);
-    FcStrSetDestroy (config->configFiles);
-    FcStrSetDestroy (config->acceptGlobs);
-    FcStrSetDestroy (config->rejectGlobs);
-    FcFontSetDestroy (config->acceptPatterns);
-    FcFontSetDestroy (config->rejectPatterns);
-
-    for (k = FcMatchKindBegin; k < FcMatchKindEnd; k++)
-	FcPtrListDestroy (config->subst[k]);
-    FcPtrListDestroy (config->rulesetList);
-    FcStrSetDestroy (config->availConfigFiles);
-    for (set = FcSetSystem; set <= FcSetApplication; set++)
-	if (config->fonts[set])
-	    FcFontSetDestroy (config->fonts[set]);
+	FcStrSetDestroy (config->configDirs);
+	FcStrSetDestroy (config->configMapDirs);
+	FcStrSetDestroy (config->fontDirs);
+	FcStrSetDestroy (config->cacheDirs);
+	FcStrSetDestroy (config->configFiles);
+	FcStrSetDestroy (config->acceptGlobs);
+	FcStrSetDestroy (config->rejectGlobs);
+	FcFontSetDestroy (config->acceptPatterns);
+	FcFontSetDestroy (config->rejectPatterns);
 
-    page = config->expr_pool;
-    while (page)
-    {
-      FcExprPage *next = page->next_page;
-      free (page);
-      page = next;
-    }
-    if (config->sysRoot)
+	for (k = FcMatchKindBegin; k < FcMatchKindEnd; k++)
+	    FcPtrListDestroy (config->subst[k]);
+	FcPtrListDestroy (config->rulesetList);
+	FcStrSetDestroy (config->availConfigFiles);
+	for (set = FcSetSystem; set <= FcSetApplication; set++)
+	    if (config->fonts[set])
+		FcFontSetDestroy (config->fonts[set]);
+
+	page = config->expr_pool;
+	while (page)
+	{
+	    FcExprPage *next = page->next_page;
+	    free (page);
+	    page = next;
+	}
+	if (config->sysRoot)
 	FcStrFree (config->sysRoot);
 
-    free (config);
+	free (config);
+    }
 }
 
 /*
@@ -421,7 +424,7 @@ FcConfigAddCache (FcConfig *config, FcCache *cache,
     if (fs)
     {
 	int	nref = 0;
-	
+
 	for (i = 0; i < fs->nfont; i++)
 	{
 	    FcPattern	*font = FcFontSetFont (fs, i);
@@ -505,7 +508,7 @@ FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet)
     dirlist = FcStrListCreate (dirSet);
     if (!dirlist)
         return FcFalse;
-	
+
     while ((dir = FcStrListNext (dirlist)))
     {
 	if (FcDebug () & FC_DBG_FONTSET)
@@ -534,7 +537,7 @@ FcConfigBuildFonts (FcConfig *config)
     config = FcConfigReference (config);
     if (!config)
 	return FcFalse;
-	
+
     fonts = FcFontSetCreate ();
     if (!fonts)
     {
@@ -1331,7 +1334,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
 	v.u.b = FcConfigCompareValue (&vl, e->op, &vr);
 	FcValueDestroy (vl);
 	FcValueDestroy (vr);
-	break;	
+	break;
     case FcOpOr:
     case FcOpAnd:
     case FcOpPlus:
@@ -1347,7 +1350,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
 	    switch ((int) vle.type) {
 	    case FcTypeDouble:
 		switch ((int) op) {
-		case FcOpPlus:	
+		case FcOpPlus:
 		    v.type = FcTypeDouble;
 		    v.u.d = vle.u.d + vre.u.d;
 		    break;
@@ -1396,7 +1399,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
 		    str = FcStrPlus (vle.u.s, vre.u.s);
 		    v.u.s = FcStrdup (str);
 		    FcStrFree (str);
-			
+
 		    if (!v.u.s)
 			v.type = FcTypeVoid;
 		    break;
@@ -2829,7 +2832,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
 	}
 	FcConfigSetFonts (config, set, FcSetApplication);
     }
-	
+
     if (!FcFileScanConfig (set, subdirs, file, config))
     {
 	FcStrSetDestroy (subdirs);
diff --git a/src/fcfs.c b/src/fcfs.c
index 21c6c7c..a9c7aac 100644
--- a/src/fcfs.c
+++ b/src/fcfs.c
@@ -42,13 +42,16 @@ FcFontSetCreate (void)
 void
 FcFontSetDestroy (FcFontSet *s)
 {
-    int	    i;
+    if (s)
+    {
+	int	    i;
 
-    for (i = 0; i < s->nfont; i++)
-	FcPatternDestroy (s->fonts[i]);
-    if (s->fonts)
-	free (s->fonts);
-    free (s);
+	for (i = 0; i < s->nfont; i++)
+	    FcPatternDestroy (s->fonts[i]);
+	if (s->fonts)
+	    free (s->fonts);
+	free (s);
+    }
 }
 
 FcBool
diff --git a/src/fclist.c b/src/fclist.c
index 51634ce..ecf4495 100644
--- a/src/fclist.c
+++ b/src/fclist.c
@@ -92,14 +92,17 @@ FcObjectSetDestroy (FcObjectSet *os)
 {
     int i;
 
-    if (os->objects)
+    if (os)
     {
-	for (i = 0; i < os->nobject; i++)
-	    FcFree (os->objects[i]);
+	if (os->objects)
+	{
+	    for (i = 0; i < os->nobject; i++)
+		FcFree (os->objects[i]);
 
-	free ((void *) os->objects);
+	    free ((void *) os->objects);
+	}
+	free (os);
     }
-    free (os);
 }
 
 FcObjectSet *
diff --git a/src/fcpat.c b/src/fcpat.c
index 82c6bed..cdbeec4 100644
--- a/src/fcpat.c
+++ b/src/fcpat.c
@@ -533,17 +533,17 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
 		p->size++;
 	    }
 	}
-	
+
 	e = FcPatternElts(p);
 	/* move elts up */
 	memmove (e + i + 1,
 		 e + i,
 		 sizeof (FcPatternElt) *
 		 (FcPatternObjectCount (p) - i));
-		
+
 	/* bump count */
 	p->num++;
-	
+
 	e[i].object = object;
 	e[i].values = NULL;
     }
@@ -1559,7 +1559,7 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
 							  FcValueList);
 	else
 	    head_serialized = vl_serialized;
-	
+
 	vl_serialized->next = NULL;
 	vl_serialized->value.type = vl->value.type;
 	switch ((int) vl->value.type) {
diff --git a/src/fcptrlist.c b/src/fcptrlist.c
index bb88832..07428a4 100644
--- a/src/fcptrlist.c
+++ b/src/fcptrlist.c
@@ -57,15 +57,18 @@ FcPtrListDestroy (FcPtrList *list)
 {
     FcPtrListIter iter;
 
-    FcPtrListIterInit (list, &iter);
-    do
+    if (list)
     {
-	if (FcPtrListIterGetValue (list, &iter))
-	    list->destroy_func (FcPtrListIterGetValue (list, &iter));
-	FcPtrListIterRemove (list, &iter);
-    } while (FcPtrListIterIsValid (list, &iter));
+	FcPtrListIterInit (list, &iter);
+	do
+	{
+	    if (FcPtrListIterGetValue (list, &iter))
+		list->destroy_func (FcPtrListIterGetValue (list, &iter));
+	    FcPtrListIterRemove (list, &iter);
+	} while (FcPtrListIterIsValid (list, &iter));
 
-    free (list);
+	free (list);
+    }
 }
 
 void
diff --git a/src/fcrange.c b/src/fcrange.c
index 8689930..0dc3d3b 100644
--- a/src/fcrange.c
+++ b/src/fcrange.c
@@ -56,7 +56,8 @@ FcRangeCreateInteger (FcChar32 begin, FcChar32 end)
 void
 FcRangeDestroy (FcRange *range)
 {
-    free (range);
+    if (range)
+	free (range);
 }
 
 FcRange *
diff --git a/src/fcstr.c b/src/fcstr.c
index 5ce65da..8f756af 100644
--- a/src/fcstr.c
+++ b/src/fcstr.c
@@ -122,7 +122,7 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
 	    int		mid = (min + max) >> 1;
 	    FcChar32    low = fcCaseFold[mid].upper;
 	    FcChar32    high = low + FcCaseFoldUpperCount (&fcCaseFold[mid]);
-	
+
 	    if (high <= ucs4)
 		min = mid + 1;
 	    else if (ucs4 < low)
@@ -131,7 +131,7 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
 	    {
 		const FcCaseFold    *fold = &fcCaseFold[mid];
 		int		    dlen;
-		
+
 		switch (fold->method) {
 		case  FC_CASE_FOLD_EVEN_ODD:
 		    if ((ucs4 & 1) != (fold->upper & 1))
@@ -145,10 +145,10 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
 		    memcpy (w->utf8, fcCaseFoldChars + fold->offset, dlen);
 		    break;
 		}
-		
+
 		/* consume rest of src utf-8 bytes */
 		w->src += slen - 1;
-		
+
 		/* read from temp buffer */
 		w->utf8[dlen] = '\0';
 		w->read = w->utf8;
@@ -441,7 +441,7 @@ FcStrContainsWord (const FcChar8 *s1, const FcChar8 *s2)
     FcBool  wordStart = FcTrue;
     int	    s1len = strlen ((char *) s1);
     int	    s2len = strlen ((char *) s2);
-	
+
     while (s1len >= s2len)
     {
 	if (wordStart &&
@@ -684,10 +684,10 @@ FcUtf8ToUcs4 (const FcChar8 *src_orig,
     {
 	result <<= 6;
 	s = *src++;
-	
+
 	if ((s & 0xc0) != 0x80)
 	    return -1;
-	
+
 	result |= s & 0x3f;
     }
     *dst = result;
@@ -1590,20 +1590,23 @@ FcStrSetReference (FcStrSet *set)
 void
 FcStrSetDestroy (FcStrSet *set)
 {
-    int	i;
+    if (set)
+    {
+	int	i;
 
-    /* We rely on this in FcGetDefaultLangs for caching. */
-    if (FcRefIsConst (&set->ref))
-	return;
+	/* We rely on this in FcGetDefaultLangs for caching. */
+	if (FcRefIsConst (&set->ref))
+	    return;
 
-    if (FcRefDec (&set->ref) != 1)
-	return;
+	if (FcRefDec (&set->ref) != 1)
+	    return;
 
-    for (i = 0; i < set->num; i++)
-	FcStrFree (set->strs[i]);
-    if (set->strs)
-	free (set->strs);
-    free (set);
+	for (i = 0; i < set->num; i++)
+	    FcStrFree (set->strs[i]);
+	if (set->strs)
+	    free (set->strs);
+	free (set);
+    }
 }
 
 FcStrList *



[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux