From 9460dc7dc05e9570c9980faa95621873215ca7d8 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 3 Sep 2008 18:31:03 -0700 Subject: [PATCH 1/2] gdi32: Protect child_font_list with its own lock. --- dlls/gdi32/freetype.c | 28 ++++++++++++++++++++++------ 1 files changed, 22 insertions(+), 6 deletions(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index cb351db..71703dd 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -462,6 +462,15 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static CRITICAL_SECTION freetype_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; +static CRITICAL_SECTION freetype_cs_child; +static CRITICAL_SECTION_DEBUG critsect_child_debug = +{ + 0, 0, &freetype_cs_child, + { &critsect_child_debug.ProcessLocksList, &critsect_child_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": freetype_cs_child") } +}; +static CRITICAL_SECTION freetype_cs_child = { &critsect_child_debug, -1, 0, 0, 0, 0 }; + static const WCHAR font_mutex_nameW[] = {'_','_','W','I','N','E','_','F','O','N','T','_','M','U','T','E','X','_','_','\0'}; static const WCHAR szDefaultFallbackLink[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f',0}; @@ -3251,7 +3260,7 @@ GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont) FMAT2 dcmat; FontSubst *psub = NULL; - EnterCriticalSection( &freetype_cs ); + EnterCriticalSection( &freetype_cs_child ); LIST_FOR_EACH_ENTRY(ret, &child_font_list, struct tagGdiFont, entry) { @@ -3259,14 +3268,14 @@ GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont) hflist = LIST_ENTRY(first_hfont, HFONTLIST, entry); if(hflist->hfont == hfont) { - LeaveCriticalSection( &freetype_cs ); + LeaveCriticalSection( &freetype_cs_child ); return ret; } } + LeaveCriticalSection( &freetype_cs_child ); if (!GetObjectW( hfont, sizeof(lf), &lf )) { - LeaveCriticalSection( &freetype_cs ); return NULL; } lf.lfWidth = abs(lf.lfWidth); @@ -3294,11 +3303,13 @@ GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont) /* check the cache first */ if((ret = find_in_cache(hfont, &lf, &dcmat, can_use_bitmap)) != NULL) { TRACE("returning cached gdiFont(%p) for hFont %p\n", ret, hfont); - LeaveCriticalSection( &freetype_cs ); return ret; } TRACE("not in cache\n"); + + EnterCriticalSection( &freetype_cs ); + if(list_empty(&font_list)) /* No fonts installed */ { TRACE("No fonts installed\n"); @@ -3657,7 +3668,7 @@ BOOL WineEngDestroyFontInstance(HFONT handle) struct list *font_elem_ptr, *hfontlist_elem_ptr; int i = 0; - EnterCriticalSection( &freetype_cs ); + EnterCriticalSection( &freetype_cs_child ); LIST_FOR_EACH_ENTRY(gdiFont, &child_font_list, struct tagGdiFont, entry) { @@ -3667,10 +3678,13 @@ BOOL WineEngDestroyFontInstance(HFONT handle) { TRACE("removing child font %p from child list\n", gdiFont); list_remove(&gdiFont->entry); - LeaveCriticalSection( &freetype_cs ); + LeaveCriticalSection( &freetype_cs_child ); return TRUE; } } + LeaveCriticalSection( &freetype_cs_child ); + + EnterCriticalSection( &freetype_cs ); TRACE("destroying hfont=%p\n", handle); if(TRACE_ON(font)) @@ -5325,7 +5339,9 @@ static BOOL load_child_font(GdiFont *font, CHILD_FONT *child) hfontlist->hfont = CreateFontIndirectW(&font->font_desc.lf); list_add_head(&child->font->hfontlist, &hfontlist->entry); child->font->base_font = font; + EnterCriticalSection( &freetype_cs_child ); list_add_head(&child_font_list, &child->font->entry); + LeaveCriticalSection( &freetype_cs_child ); TRACE("created child font hfont %p for base %p child %p\n", hfontlist->hfont, font, child->font); return TRUE; } -- 1.5.4.5