From c83329cdf1c37fd1ee123a0f30e8b6582ac51547 Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Sat, 28 Sep 2013 17:24:31 -0300 Subject: prevent redundant firing of InitTheFace (pFont never changes, but init is called all over the place); also some nulling and freeing to prevent leaks, and removing the redundant daddy unreffing that is done in ~FontInstance anyway (bzr r12618) --- src/libnrtype/FontInstance.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libnrtype') diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index fd0cdd3d4..38a105459 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -192,6 +192,7 @@ font_instance::~font_instance(void) //printf("font instance death\n"); if ( pFont ) { + FreeTheFace(); g_object_unref(pFont); pFont = 0; } @@ -232,10 +233,6 @@ void font_instance::Unref(void) //printf("font %x %s unref'd %i\n",this,tc,refCount); //free(tc); if ( refCount <= 0 ) { - if ( daddy ) { - daddy->UnrefFace(this); - } - daddy=NULL; delete this; } } @@ -387,6 +384,7 @@ unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int void font_instance::InitTheFace() { + if (theFace == NULL && pFont != NULL) { #ifdef USE_PANGO_WIN32 if ( !theFace ) { LOGFONT *lf=pango_win32_font_logfont(pFont); @@ -404,6 +402,7 @@ void font_instance::InitTheFace() FT_Select_Charmap(theFace,ft_encoding_unicode) && FT_Select_Charmap(theFace,ft_encoding_symbol); } #endif + } } void font_instance::FreeTheFace() @@ -423,6 +422,7 @@ void font_instance::InstallFace(PangoFont* iFace) return; } pFont=iFace; + iFace = NULL; InitTheFace(); -- cgit v1.2.3 From 6cc0d44d20de8e537e42dac66de344354ea80d1c Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Sat, 28 Sep 2013 17:26:16 -0300 Subject: order correction: unreffing fonts in ents needs loadedPtr so that must go before loadedPrt is nulled; this didn't crash simply because we never freed FontFactory before; also some comments and remove redundant multiply in hash function (bzr r12619) --- src/libnrtype/FontFactory.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/libnrtype') diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index c896cc470..9fc553efd 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -25,7 +25,6 @@ typedef INK_UNORDERED_MAP(g_malloc(maxEnt*sizeof(font_entry)))), @@ -327,12 +326,6 @@ font_factory::font_factory(void) : font_factory::~font_factory(void) { - if (loadedPtr) { - FaceMapType* tmp = static_cast(loadedPtr); - delete tmp; - loadedPtr = 0; - } - for (int i = 0;i < nbEnt;i++) ents[i].f->Unref(); if ( ents ) g_free(ents); @@ -344,6 +337,12 @@ font_factory::~font_factory(void) #endif //g_object_unref(fontContext); + if (loadedPtr) { + FaceMapType* tmp = static_cast(loadedPtr); + delete tmp; + loadedPtr = 0; + } + // Delete the pango font pointers in the string to instance map PangoStringToDescrMap::iterator it = fontInstanceMap.begin(); while (it != fontInstanceMap.end()) { @@ -1126,7 +1125,7 @@ void font_factory::AddInCache(font_instance *who) return; } who->Ref(); - if ( nbEnt == maxEnt ) { + if ( nbEnt == maxEnt ) { // cache is filled, unref the oldest-accessed font in it int bi = 0; double ba = ents[bi].age; for (int i = 1;i < nbEnt;i++) { -- cgit v1.2.3 From 6b8c701e9d74cff5c0b2eaa2b678d8e9f7410658 Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Sat, 28 Sep 2013 17:27:10 -0300 Subject: FontInstances were being leaked here by overreffing - every call to Face must unref when done (bzr r12620) --- src/libnrtype/Layout-TNG-Compute.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libnrtype') diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp index 7ea089c93..973db0165 100644 --- a/src/libnrtype/Layout-TNG-Compute.cpp +++ b/src/libnrtype/Layout-TNG-Compute.cpp @@ -980,6 +980,7 @@ void Layout::Calculator::_buildPangoItemizationForPara(ParagraphInfo *para) con attribute_font_description->end_index = para_text.bytes(); pango_attr_list_insert(attributes_list, attribute_font_description); // ownership of attribute is assumed by the list + font->Unref(); } } -- cgit v1.2.3