From 13a14cbf56d56c14d53e5f55d7fcc4bdec900994 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 4 May 2008 01:26:40 -0700 Subject: [PATCH] Fix a few memory tracking mistakes. The built-in memory tracking code in fontconfig relies on a lot of manual function call tracking. A pain, but it helps debug leaks. --- src/fcatomic.c | 2 +- src/fccharset.c | 6 ++++++ src/fcinit.c | 2 ++ src/fcpat.c | 2 +- src/fcstr.c | 9 +++++++-- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/fcatomic.c b/src/fcatomic.c index 9038a5f..8c04510 100644 --- a/src/fcatomic.c +++ b/src/fcatomic.c @@ -205,7 +205,7 @@ void FcAtomicDestroy (FcAtomic *atomic) { FcMemFree (FC_MEM_ATOMIC, sizeof (FcAtomic) + - strlen ((char *) atomic->file) * 4 + 1 + + strlen ((char *) atomic->file) * 4 + 4 + sizeof (NEW_NAME) + sizeof (LCK_NAME) + sizeof (TMP_NAME)); diff --git a/src/fccharset.c b/src/fccharset.c index 5da1312..f4042db 100644 --- a/src/fccharset.c +++ b/src/fccharset.c @@ -1239,6 +1239,9 @@ FcCharSetFreezerDestroy (FcCharSetFreezer *freezer) for (ent = freezer->set_hash_table[i]; ent; ent = next) { next = ent->next; + FcMemFree (FC_MEM_CHARSET, (sizeof (FcCharSetEnt) + + ent->set.num * sizeof (FcCharLeaf *) + + ent->set.num * sizeof (FcChar16))); free (ent); } } @@ -1254,7 +1257,10 @@ FcCharSetFreezerDestroy (FcCharSetFreezer *freezer) } for (i = 0; i < freezer->leaf_block_count; i++) + { free (freezer->leaf_blocks[i]); + FcMemFree (FC_MEM_CHARLEAF, FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt)); + } free (freezer->leaf_blocks); free (freezer); diff --git a/src/fcinit.c b/src/fcinit.c index 96aaa44..0998abc 100644 --- a/src/fcinit.c +++ b/src/fcinit.c @@ -141,6 +141,8 @@ FcFini (void) FcPatternFini (); FcCacheFini (); + if (FcDebug() & FC_DBG_MEMORY) + FcMemReport (); } /* diff --git a/src/fcpat.c b/src/fcpat.c index 9a62ec9..35127f2 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -1054,7 +1054,7 @@ FcStrStaticNameFini (void) next = b->next; name = (char *) (b + 1); size = sizeof (struct objectBucket) + strlen (name) + 1; - FcMemFree (FC_MEM_STATICSTR, size); + FcMemFree (FC_MEM_STATICSTR, size + sizeof (int)); free (b); } FcObjectBuckets[i] = 0; diff --git a/src/fcstr.c b/src/fcstr.c index 1e7b466..f56f823 100644 --- a/src/fcstr.c +++ b/src/fcstr.c @@ -1025,11 +1025,14 @@ _FcStrSetAppend (FcStrSet *set, FcChar8 *s) if (!strs) return FcFalse; FcMemAlloc (FC_MEM_STRSET, (set->size + 2) * sizeof (FcChar8 *)); - set->size = set->size + 1; if (set->num) memcpy (strs, set->strs, set->num * sizeof (FcChar8 *)); if (set->strs) + { + FcMemFree (FC_MEM_STRSET, (set->size + 1) * sizeof (FcChar8 *)); free (set->strs); + } + set->size = set->size + 1; set->strs = strs; } set->strs[set->num++] = s; @@ -1118,9 +1121,11 @@ FcStrSetDestroy (FcStrSet *set) for (i = 0; i < set->num; i++) FcStrFree (set->strs[i]); - FcMemFree (FC_MEM_STRSET, (set->size) * sizeof (FcChar8 *)); if (set->strs) + { + FcMemFree (FC_MEM_STRSET, (set->size + 1) * sizeof (FcChar8 *)); free (set->strs); + } FcMemFree (FC_MEM_STRSET, sizeof (FcStrSet)); free (set); } -- 2.39.5