From 7e17be41af312c584afde7a428f61445adabc8b0 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 3 Sep 2008 18:35:36 -0700 Subject: [PATCH 2/2] gdi32: Protect gdi_font_list/unused_gdi_font_list with its own lock. --- dlls/gdi32/freetype.c | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 71703dd..a003397 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -471,6 +471,15 @@ static CRITICAL_SECTION_DEBUG critsect_child_debug = }; static CRITICAL_SECTION freetype_cs_child = { &critsect_child_debug, -1, 0, 0, 0, 0 }; +static CRITICAL_SECTION freetype_cs_gdi; +static CRITICAL_SECTION_DEBUG critsect_gdi_debug = +{ + 0, 0, &freetype_cs_gdi, + { &critsect_gdi_debug.ProcessLocksList, &critsect_gdi_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": freetype_cs_gdi") } +}; +static CRITICAL_SECTION freetype_cs_gdi = { &critsect_gdi_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}; @@ -3086,6 +3095,7 @@ static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const FMAT2 *pma fd.can_use_bitmap = can_use_bitmap; calc_hash(&fd); + EnterCriticalSection( &freetype_cs_gdi ); /* try the in-use list */ LIST_FOR_EACH(font_elem_ptr, &gdi_font_list) { ret = LIST_ENTRY(font_elem_ptr, struct tagGdiFont, entry); @@ -3094,12 +3104,12 @@ static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const FMAT2 *pma LIST_FOR_EACH(hfontlist_elem_ptr, &ret->hfontlist) { hflist = LIST_ENTRY(hfontlist_elem_ptr, struct tagHFONTLIST, entry); if(hflist->hfont == hfont) - return ret; + goto find_in_cache_done; } hflist = HeapAlloc(GetProcessHeap(), 0, sizeof(*hflist)); hflist->hfont = hfont; list_add_head(&ret->hfontlist, &hflist->entry); - return ret; + goto find_in_cache_done; } } @@ -3117,18 +3127,25 @@ static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const FMAT2 *pma hflist = HeapAlloc(GetProcessHeap(), 0, sizeof(*hflist)); hflist->hfont = hfont; list_add_head(&ret->hfontlist, &hflist->entry); - return ret; + goto find_in_cache_done; } } + LeaveCriticalSection( &freetype_cs_gdi ); return NULL; + +find_in_cache_done: + LeaveCriticalSection( &freetype_cs_gdi ); + return ret; } static void add_to_cache(GdiFont *font) { static DWORD cache_num = 1; + EnterCriticalSection( &freetype_cs_gdi ); font->cache_num = cache_num++; list_add_head(&gdi_font_list, &font->entry); + LeaveCriticalSection( &freetype_cs_gdi ); } /************************************************************* @@ -3639,6 +3656,7 @@ static void dump_gdi_font_list(void) GdiFont *gdiFont; struct list *elem_ptr; + EnterCriticalSection( &freetype_cs_gdi ); TRACE("---------- gdiFont Cache ----------\n"); LIST_FOR_EACH(elem_ptr, &gdi_font_list) { gdiFont = LIST_ENTRY(elem_ptr, struct tagGdiFont, entry); @@ -3652,6 +3670,7 @@ static void dump_gdi_font_list(void) TRACE("gdiFont=%p %s %d\n", gdiFont, debugstr_w(gdiFont->font_desc.lf.lfFaceName), gdiFont->font_desc.lf.lfHeight); } + LeaveCriticalSection( &freetype_cs_gdi ); } /************************************************************* @@ -3684,12 +3703,11 @@ BOOL WineEngDestroyFontInstance(HFONT handle) } LeaveCriticalSection( &freetype_cs_child ); - EnterCriticalSection( &freetype_cs ); - TRACE("destroying hfont=%p\n", handle); if(TRACE_ON(font)) dump_gdi_font_list(); + EnterCriticalSection( &freetype_cs_gdi ); font_elem_ptr = list_head(&gdi_font_list); while(font_elem_ptr) { gdiFont = LIST_ENTRY(font_elem_ptr, struct tagGdiFont, entry); @@ -3723,7 +3741,7 @@ BOOL WineEngDestroyFontInstance(HFONT handle) list_remove(&gdiFont->entry); free_font(gdiFont); } - LeaveCriticalSection( &freetype_cs ); + LeaveCriticalSection( &freetype_cs_gdi ); return ret; } -- 1.5.4.5