From c9d1f9a71948af7cd028d9ef499cb13e9d9b8f0d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 13 Nov 2017 21:44:34 +0100 Subject: [PATCH] Clean up FcConfig object on library shutdown Don't just leak it as was done before. --- src/gtk/font.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 5d58852125..2887537728 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -561,6 +561,7 @@ bool wxFont::GTKSetPangoAttrs(PangoLayout* layout) const #ifdef wxHAS_PRIVATE_FONTS #include "wx/fontenum.h" +#include "wx/module.h" #include "wx/gtk/private.h" #include "wx/gtk/private/object.h" @@ -571,8 +572,32 @@ extern PangoContext* wxGetPangoContext(); namespace { - FcConfig* gs_fcConfig = NULL; -} + +FcConfig* gs_fcConfig = NULL; + +// Module used to clean up the global FcConfig. +class wxFcConfigDestroyModule : public wxModule +{ +public: + wxFcConfigDestroyModule() { } + + bool OnInit() wxOVERRIDE { return true; } + void OnExit() wxOVERRIDE + { + if ( gs_fcConfig ) + { + FcConfigDestroy(gs_fcConfig); + gs_fcConfig = NULL; + } + } + +private: + wxDECLARE_DYNAMIC_CLASS(wxFcConfigDestroyModule); +}; + +wxIMPLEMENT_DYNAMIC_CLASS(wxFcConfigDestroyModule, wxModule); + +} // anonymous namespace bool wxFontBase::AddPrivateFont(const wxString& filename) {