From: Jeff Smith Subject: [PATCH 2/2] gdiplus: Guard initialization of installed font collection. Message-Id: <20201119163557.956404-2-whydoubt@gmail.com> Date: Thu, 19 Nov 2020 10:35:57 -0600 In-Reply-To: <20201119163557.956404-1-whydoubt@gmail.com> References: <20201119163557.956404-1-whydoubt@gmail.com> Signed-off-by: Jeff Smith --- Without this GdipNewInstalledFontCollection may return a partial collection, if called while another thread is initializing it. dlls/gdiplus/font.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c index 4301fa3aaa3..05663b71aad 100644 --- a/dlls/gdiplus/font.c +++ b/dlls/gdiplus/font.c @@ -117,6 +117,15 @@ typedef struct static GpFontCollection installedFontCollection = {0}; +static CRITICAL_SECTION font_cs; +static CRITICAL_SECTION_DEBUG critsect_debug = +{ + 0, 0, &font_cs, + { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": font_cs") } +}; +static CRITICAL_SECTION font_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; + /******************************************************************************* * GdipCreateFont [GDIPLUS.@] * @@ -1648,6 +1657,7 @@ GpStatus WINGDIPAPI GdipNewInstalledFontCollection( if (!fontCollection) return InvalidParameter; + EnterCriticalSection( &font_cs ); if (installedFontCollection.count == 0) { struct add_font_param param; @@ -1665,11 +1675,13 @@ GpStatus WINGDIPAPI GdipNewInstalledFontCollection( { free_installed_fonts(); DeleteDC(param.hdc); + LeaveCriticalSection( &font_cs ); return param.stat; } DeleteDC(param.hdc); } + LeaveCriticalSection( &font_cs ); *fontCollection = &installedFontCollection; -- 2.23.0