[Commit] fontconfig/src fccfg.c, 1.40, 1.41 fccharset.c, 1.23, 1.24 fcinit.c, 1.9, 1.10 fcint.h, 1.40, 1.41 fcpat.c, 1.21, 1.22 fcxml.c, 1.30, 1.31 fontconfig.def.in, 1.2, 1.3

Carl Worth commit at keithp.com
Fri Aug 15 13:45:23 PDT 2003


Committed by: cworth

Update of /local/src/CVS/fontconfig/src
In directory home.keithp.com:/tmp/cvs-serv29091/src

Modified Files:
	fccfg.c fccharset.c fcinit.c fcint.h fcpat.c fcxml.c 
	fontconfig.def.in 
Log Message:
Added new FcFini function for cleaning up all memory.
Fixed a few memory leaks.
fc-list now calls FcFini, (and is now leak-free according to valgrind)

Index: fccfg.c
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fccfg.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- fccfg.c	20 Jul 2003 16:06:18 -0000	1.40
+++ fccfg.c	15 Aug 2003 19:45:20 -0000	1.41
@@ -160,6 +160,8 @@
 	    FcTestDestroy (s->test);
 	if (s->edit)
 	    FcEditDestroy (s->edit);
+	free (s);
+	FcMemFree (FC_MEM_SUBST, sizeof (FcSubst));
 	s = n;
     }
 }
@@ -178,6 +180,9 @@
     FcStrSetDestroy (config->acceptGlobs);
     FcStrSetDestroy (config->rejectGlobs);
 
+    if (config->blanks)
+	FcBlanksDestroy (config->blanks);
+
     if (config->cache)
 	FcStrFree (config->cache);
 
@@ -186,6 +191,7 @@
     for (set = FcSetSystem; set <= FcSetApplication; set++)
 	if (config->fonts[set])
 	    FcFontSetDestroy (config->fonts[set]);
+
     free (config);
     FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
 }

Index: fccharset.c
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fccharset.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- fccharset.c	24 Apr 2003 15:29:33 -0000	1.23
+++ fccharset.c	15 Aug 2003 19:45:20 -0000	1.24
@@ -845,6 +845,8 @@
 };
 
 #define FC_CHAR_LEAF_BLOCK	(4096 / sizeof (FcCharLeafEnt))
+static FcCharLeafEnt **FcCharLeafBlocks;
+static int FcCharLeafBlockCount;
 
 static FcCharLeafEnt *
 FcCharLeafEntCreate (void)
@@ -854,7 +856,14 @@
 
     if (!remain)
     {
-	block = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
+	FcCharLeafEnt **newBlocks;
+
+	FcCharLeafBlockCount++;
+	newBlocks = realloc (FcCharLeafBlocks, FcCharLeafBlockCount * sizeof (FcCharLeafEnt *));
+	if (!newBlocks)
+	    return 0;
+	FcCharLeafBlocks = newBlocks;
+	block = FcCharLeafBlocks[FcCharLeafBlockCount-1] = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
 	if (!block)
 	    return 0;
 	FcMemAlloc (FC_MEM_CHARLEAF, FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
@@ -880,12 +889,13 @@
 static int	FcCharLeafTotal;
 static int	FcCharLeafUsed;
 
+static FcCharLeafEnt	*FcCharLeafHashTable[FC_CHAR_LEAF_HASH_SIZE];
+
 static FcCharLeaf *
 FcCharSetFreezeLeaf (FcCharLeaf *leaf)
 {
-    static FcCharLeafEnt	*hashTable[FC_CHAR_LEAF_HASH_SIZE];
     FcChar32			hash = FcCharLeafHash (leaf);
-    FcCharLeafEnt		**bucket = &hashTable[hash % FC_CHAR_LEAF_HASH_SIZE];
+    FcCharLeafEnt		**bucket = &FcCharLeafHashTable[hash % FC_CHAR_LEAF_HASH_SIZE];
     FcCharLeafEnt		*ent;
     
     FcCharLeafTotal++;
@@ -906,6 +916,25 @@
     return &ent->leaf;
 }
 
+static void
+FcCharSetThawAllLeaf (void)
+{
+    int i;
+
+    for (i = 0; i < FC_CHAR_LEAF_HASH_SIZE; i++)
+	FcCharLeafHashTable[i] = 0;
+
+    FcCharLeafTotal = 0;
+    FcCharLeafUsed = 0;
+
+    for (i = 0; i < FcCharLeafBlockCount; i++)
+	free (FcCharLeafBlocks[i]);
+
+    free (FcCharLeafBlocks);
+    FcCharLeafBlocks = 0;
+    FcCharLeafBlockCount = 0;
+}
+
 typedef struct _FcCharSetEnt FcCharSetEnt;
 
 struct _FcCharSetEnt {
@@ -937,12 +966,13 @@
 static int	FcCharSetUsed;
 static int	FcCharSetTotalEnts, FcCharSetUsedEnts;
 
+static FcCharSetEnt	*FcCharSetHashTable[FC_CHAR_SET_HASH_SIZE];
+
 static FcCharSet *
 FcCharSetFreezeBase (FcCharSet *fcs)
 {
-    static FcCharSetEnt	*hashTable[FC_CHAR_SET_HASH_SIZE];
     FcChar32		hash = FcCharSetHash (fcs);
-    FcCharSetEnt	**bucket = &hashTable[hash % FC_CHAR_SET_HASH_SIZE];
+    FcCharSetEnt	**bucket = &FcCharSetHashTable[hash % FC_CHAR_SET_HASH_SIZE];
     FcCharSetEnt	*ent;
     int			size;
 
@@ -992,6 +1022,30 @@
     return &ent->set;
 }
 
+void
+FcCharSetThawAll (void)
+{
+    int i;
+    FcCharSetEnt	*ent, *next;
+
+    for (i = 0; i < FC_CHAR_SET_HASH_SIZE; i++)
+    {
+	for (ent = FcCharSetHashTable[i]; ent; ent = next)
+	{
+	    next = ent->next;
+	    free (ent);
+	}
+	FcCharSetHashTable[i] = 0;
+    }
+
+    FcCharSetTotal = 0;
+    FcCharSetTotalEnts = 0;
+    FcCharSetUsed = 0;
+    FcCharSetUsedEnts = 0;
+
+    FcCharSetThawAllLeaf ();
+}
+
 FcCharSet *
 FcCharSetFreeze (FcCharSet *fcs)
 {

Index: fcinit.c
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fcinit.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- fcinit.c	5 Mar 2003 05:51:27 -0000	1.9
+++ fcinit.c	15 Aug 2003 19:45:20 -0000	1.10
@@ -108,6 +108,19 @@
 }
 
 /*
+ * Free all library-allocated data structures.
+ */
+void
+FcFini (void)
+{
+    if (_fcConfig)
+	FcConfigDestroy (_fcConfig);
+
+    FcPatternThawAll ();
+    FcCharSetThawAll ();
+}
+
+/*
  * Reread the configuration and available font lists
  */
 FcBool

Index: fcint.h
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fcint.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- fcint.h	20 Jul 2003 16:06:18 -0000	1.40
+++ fcint.h	15 Aug 2003 19:45:20 -0000	1.41
@@ -469,6 +469,9 @@
 FcCharSet *
 FcCharSetFreeze (FcCharSet *cs);
 
+void
+FcCharSetThawAll (void);
+
 FcBool
 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
 
@@ -663,6 +666,9 @@
 FcPattern *
 FcPatternFreeze (FcPattern *p);
 
+void
+FcPatternThawAll (void);
+
 /* fcrender.c */
 
 /* fcmatrix.c */

Index: fcpat.c
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fcpat.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- fcpat.c	5 Mar 2003 05:51:27 -0000	1.21
+++ fcpat.c	15 Aug 2003 19:45:20 -0000	1.22
@@ -366,15 +366,43 @@
     return e;
 }
 
+static void
+FcValueListEntDestroy (FcValueListEnt *e)
+{
+    FcValueList	*l;
+
+    FcValueListFrozenCount[e->list->value.type]--;
+
+    /* XXX: We should perform these two operations with "size" as
+       computed in FcValueListEntCreate, but we don't have access to
+       that value here. Without this, the FcValueListFrozenBytes
+       values will be wrong as will the FcMemFree counts.
+
+       FcValueListFrozenBytes[e->list->value.type] -= size;
+       FcMemFree (FC_MEM_VALLIST, size);
+    */
+
+    for (l = e->list; l; l = l->next)
+    {
+	if (l->value.type != FcTypeString)
+	    FcValueDestroy (l->value);
+    }
+    /* XXX: Are we being too chummy with the implementation here to
+       free(e) when it was actually the enclosing FcValueListAlign
+       that was allocated? */
+    free (e);
+}
+
 static int	FcValueListTotal;
 static int	FcValueListUsed;
 
+static FcValueListEnt   *FcValueListHashTable[FC_VALUE_LIST_HASH_SIZE];
+
 static FcValueList *
 FcValueListFreeze (FcValueList *l)
 {
-    static FcValueListEnt   *hashTable[FC_VALUE_LIST_HASH_SIZE];
     FcChar32		    hash = FcValueListHash (l);
-    FcValueListEnt	    **bucket = &hashTable[hash % FC_VALUE_LIST_HASH_SIZE];
+    FcValueListEnt	    **bucket = &FcValueListHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
     FcValueListEnt	    *ent;
 
     FcValueListTotal++;
@@ -395,6 +423,26 @@
     return ent->list;
 }
 
+static void
+FcValueListThawAll (void)
+{
+    int i;
+    FcValueListEnt	*ent, *next;
+
+    for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
+    {
+	for (ent = FcValueListHashTable[i]; ent; ent = next)
+	{
+	    next = ent->next;
+	    FcValueListEntDestroy (ent);
+	}
+	FcValueListHashTable[i] = 0;
+    }
+
+    FcValueListTotal = 0;
+    FcValueListUsed = 0;
+}
+
 static FcChar32
 FcPatternBaseHash (FcPattern *b)
 {
@@ -417,12 +465,13 @@
 static int	FcPatternTotal;
 static int	FcPatternUsed;
 
+static FcPatternEnt	*FcPatternHashTable[FC_VALUE_LIST_HASH_SIZE];
+
 static FcPattern *
 FcPatternBaseFreeze (FcPattern *b)
 {
-    static FcPatternEnt	*hashTable[FC_VALUE_LIST_HASH_SIZE];
     FcChar32		hash = FcPatternBaseHash (b);
-    FcPatternEnt	**bucket = &hashTable[hash % FC_VALUE_LIST_HASH_SIZE];
+    FcPatternEnt	**bucket = &FcPatternHashTable[hash % FC_VALUE_LIST_HASH_SIZE];
     FcPatternEnt	*ent;
     int			i;
     char		*objects;
@@ -481,6 +530,26 @@
     return &ent->pattern;
 }
 
+static void
+FcPatternBaseThawAll (void)
+{
+    int i;
+    FcPatternEnt	*ent, *next;
+
+    for (i = 0; i < FC_VALUE_LIST_HASH_SIZE; i++)
+    {
+	for (ent = FcPatternHashTable[i]; ent; ent = next)
+	{
+	    next = ent->next;
+	    free (ent);
+	}
+	FcPatternHashTable[i] = 0;
+    }
+
+    FcPatternTotal = 0;
+    FcPatternUsed = 0;
+}
+
 FcPattern *
 FcPatternFreeze (FcPattern *p)
 {
@@ -526,6 +595,13 @@
     return n;
 }
 
+void
+FcPatternThawAll (void)
+{
+    FcPatternBaseThawAll ();
+    FcValueListThawAll ();
+}
+
 static int
 FcPatternPosition (const FcPattern *p, const char *object)
 {

Index: fcxml.c
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fcxml.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- fcxml.c	20 Jul 2003 16:06:18 -0000	1.30
+++ fcxml.c	15 Aug 2003 19:45:20 -0000	1.31
@@ -292,6 +292,7 @@
     FcStrFree ((FcChar8 *) e->field);
     if (e->expr)
 	FcExprDestroy (e->expr);
+    free (e);
 }
 
 char *
@@ -1288,6 +1289,9 @@
     case FcVStackConstant:
 	expr = FcExprCreateConst (vstack->u.string);
 	break;
+    case FcVStackGlob:
+	/* XXX: What's the correct action here? (CDW) */
+	break;
     case FcVStackPrefer:
     case FcVStackAccept:
     case FcVStackDefault:

Index: fontconfig.def.in
===================================================================
RCS file: /local/src/CVS/fontconfig/src/fontconfig.def.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- fontconfig.def.in	13 Jun 2003 22:43:28 -0000	1.2
+++ fontconfig.def.in	15 Aug 2003 19:45:20 -0000	1.3
@@ -53,6 +53,7 @@
 	FcDirSave
 	FcDirScan
 	FcFileScan
+	FcFini
 	FcFontList
 	FcFontMatch
 	FcFontRenderPrepare




More information about the Commit mailing list