From 5e385a98255f8ac1fc33cb9cd795136dfa7b89b5 Mon Sep 17 00:00:00 2001 From: Hank Fox Date: Fri, 4 Nov 2016 12:57:53 -0700 Subject: [PATCH] Fix poor comptr usage and leaks. Return to static initializer model. --- Frameworks/CoreGraphics/CGContext.mm | 4 ++-- Frameworks/CoreGraphics/CGPath.mm | 2 +- Frameworks/CoreGraphics/D2DWrapper.mm | 14 ++++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Frameworks/CoreGraphics/CGContext.mm b/Frameworks/CoreGraphics/CGContext.mm index dace77b3bb..2721e1ed20 100644 --- a/Frameworks/CoreGraphics/CGContext.mm +++ b/Frameworks/CoreGraphics/CGContext.mm @@ -1648,9 +1648,9 @@ void CGContextFillRects(CGContextRef context, const CGRect* rects, size_t count) void CGContextDrawPath(CGContextRef context, CGPathDrawingMode mode) { NOISY_RETURN_IF_NULL(context); if (context->HasPath()) { - ID2D1Geometry* pGeometry; + ComPtr pGeometry; FAIL_FAST_IF_FAILED(_CGPathGetGeometry(context->Path(), &pGeometry)); - FAIL_FAST_IF_FAILED(__CGContextDrawGeometry(context, pGeometry, mode)); + FAIL_FAST_IF_FAILED(__CGContextDrawGeometry(context, pGeometry.Get(), mode)); context->ClearPath(); } } diff --git a/Frameworks/CoreGraphics/CGPath.mm b/Frameworks/CoreGraphics/CGPath.mm index c2560a2b7f..c67a4161ee 100644 --- a/Frameworks/CoreGraphics/CGPath.mm +++ b/Frameworks/CoreGraphics/CGPath.mm @@ -152,7 +152,7 @@ HRESULT InitializeGeometries() { HRESULT _CGPathGetGeometry(CGPathRef path, ID2D1Geometry** pGeometry) { if (path && pGeometry) { RETURN_IF_FAILED(path->ClosePath()); - *pGeometry = path->GetPathGeometry().Get(); + path->GetPathGeometry().CopyTo(pGeometry); } return S_OK; } diff --git a/Frameworks/CoreGraphics/D2DWrapper.mm b/Frameworks/CoreGraphics/D2DWrapper.mm index f46cbfe05e..e225adf3cb 100644 --- a/Frameworks/CoreGraphics/D2DWrapper.mm +++ b/Frameworks/CoreGraphics/D2DWrapper.mm @@ -19,18 +19,16 @@ using namespace Microsoft::WRL; +static HRESULT __createD2DFactory(ID2D1Factory** factory) { + return D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, factory); +} + HRESULT _CGGetD2DFactory(ID2D1Factory** factory) { static ComPtr sFactory; - static HRESULT sHr; - static dispatch_once_t dispatchToken; - - dispatch_once(&dispatchToken, ^{ - sHr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), &sFactory); - }); + static HRESULT sHr = __createD2DFactory(&sFactory); - sFactory.Get()->AddRef(); sFactory.CopyTo(factory); - return sHr; + RETURN_HR(sHr); } static ComPtr __createWICFactory() {