From 23e88d8c6a5d3d0a9526a3f3217bd33a7607cbab Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Tue, 12 Aug 2014 18:48:00 +0900 Subject: [PATCH] Increase the refcount in FcConfigSetCurrent() https://bugs.freedesktop.org/show_bug.cgi?id=82432 --- fc-cat/fc-cat.c | 1 + src/fccfg.c | 5 +++++ src/fcinit.c | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c index 9a2abb3..3a303c2 100644 --- a/fc-cat/fc-cat.c +++ b/fc-cat/fc-cat.c @@ -298,6 +298,7 @@ main (int argc, char **argv) return 1; } FcConfigSetCurrent (config); + FcConfigDestroy (config); args = FcStrSetCreate (); if (!args) diff --git a/src/fccfg.c b/src/fccfg.c index f8ee8d2..55cb297 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -434,6 +434,7 @@ retry: if (!fc_atomic_ptr_cmpexch (&_fcConfig, cfg, config)) goto retry; + FcConfigReference (config); if (cfg) FcConfigDestroy (cfg); @@ -2405,6 +2406,10 @@ FcConfigSetSysRoot (FcConfig *config, { config = FcInitLoadOwnConfigAndFonts (config); FcConfigSetCurrent (config); + /* FcConfigSetCurrent() increases the refcount. + * decrease it here to avoid the memory leak. + */ + FcConfigDestroy (config); } } diff --git a/src/fcinit.c b/src/fcinit.c index 1e23c1f..db62c21 100644 --- a/src/fcinit.c +++ b/src/fcinit.c @@ -189,11 +189,18 @@ FcBool FcInitReinitialize (void) { FcConfig *config; + FcBool ret; config = FcInitLoadConfigAndFonts (); if (!config) return FcFalse; - return FcConfigSetCurrent (config); + ret = FcConfigSetCurrent (config); + /* FcConfigSetCurrent() increases the refcount. + * decrease it here to avoid the memory leak. + */ + FcConfigDestroy (config); + + return ret; } FcBool