summaryrefslogtreecommitdiff
path: root/src/fccharset.c
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2003-08-15 19:45:20 +0000
committerCarl Worth <cworth@cworth.org>2003-08-15 19:45:20 +0000
commit34cd0514a215d65af6822eba2c2f0cd04eb0065f (patch)
treec67c425f6540c2ee5b6227a0c247ea2395b817c5 /src/fccharset.c
parent18906a876aa13550b1a10550ceeef6df0c4473ec (diff)
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)
Diffstat (limited to 'src/fccharset.c')
-rw-r--r--src/fccharset.c64
1 files changed, 59 insertions, 5 deletions
diff --git a/src/fccharset.c b/src/fccharset.c
index d87a720a..a1c8f890 100644
--- a/src/fccharset.c
+++ b/src/fccharset.c
@@ -845,6 +845,8 @@ struct _FcCharLeafEnt {
};
#define FC_CHAR_LEAF_BLOCK (4096 / sizeof (FcCharLeafEnt))
+static FcCharLeafEnt **FcCharLeafBlocks;
+static int FcCharLeafBlockCount;
static FcCharLeafEnt *
FcCharLeafEntCreate (void)
@@ -854,7 +856,14 @@ FcCharLeafEntCreate (void)
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 @@ FcCharLeafHash (FcCharLeaf *leaf)
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 @@ FcCharSetFreezeLeaf (FcCharLeaf *leaf)
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 FcCharSetTotal;
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 @@ FcCharSetFreezeBase (FcCharSet *fcs)
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)
{