diff options
author | Akira TAGOH <akira@tagoh.org> | 2015-05-22 16:53:34 +0900 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2015-05-22 16:53:34 +0900 |
commit | fa6c6b53c5a42ae6a9f8254ca9603dbe0aec63ad (patch) | |
tree | c54a44f95a4e2316349cb7318e5e4a6f36c0866c /src/fcobjs.c | |
parent | bcfe167e3d60402c1f999359ca8531c6fae01a2b (diff) | |
download | fontconfig-fa6c6b53c5a42ae6a9f8254ca9603dbe0aec63ad.tar.gz |
Fix memory leaks after FcFini()
Reported by Jia Wang
https://bugs.freedesktop.org/show_bug.cgi?id=83770
Diffstat (limited to 'src/fcobjs.c')
-rw-r--r-- | src/fcobjs.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/fcobjs.c b/src/fcobjs.c index bad9824..2895dc0 100644 --- a/src/fcobjs.c +++ b/src/fcobjs.c @@ -44,6 +44,26 @@ struct FcObjectOtherTypeInfo { FcObject id; } *other_types; +void +FcObjectFini (void) +{ + struct FcObjectOtherTypeInfo *ots, *ot; + +retry: + ots = fc_atomic_ptr_get (&other_types); + if (!fc_atomic_ptr_cmpexch (&other_types, ots, NULL)) + goto retry; + + while (ots) + { + ot = ots->next; + if (ots->object.object) + free (ots->object.object); + free (ots); + ots = ot; + } +} + static FcObjectType * _FcObjectLookupOtherTypeByName (const char *str, FcObject *id) { @@ -62,13 +82,16 @@ retry: if (!ot) return NULL; - ot->object.object = (const char *) FcStrdup (str); + ot->object.object = (char *) FcStrdup (str); ot->object.type = FcTypeUnknown; ot->id = fc_atomic_int_add (next_id, +1); ot->next = ots; if (!fc_atomic_ptr_cmpexch (&other_types, ots, ot)) { + if (ot->object.object) + free (ot->object.object); free (ot); + fc_atomic_int_add (next_id, -1); goto retry; } } |