[Webkit-unassigned] [Bug 76219] New: cairo_t* memory leak in GraphicsContext::platformInit

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jan 12 15:06:58 PST 2012


https://bugs.webkit.org/show_bug.cgi?id=76219

           Summary: cairo_t* memory leak in GraphicsContext::platformInit
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: PC
               URL: http://smithmicro.com
        OS/Version: Windows 7
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: WebCore Misc.
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: bstuart at smithmicro.com


In source\webcore\platform\graphics\win\graphicscontextcairowin.cpp GraphicsContext::platformInit createCairoContextWithHDC is called returning a cairo_t* which has a reference count of 1. Passing that cairo_t* to PlatformContextCairo's ctor causes the reference count to increment to 2. Now when ~PlatformContextCairo is called it's cairo_t* is leaked.

Here is my workaround, a better solution would involve using adoptRef and passing a RefPtr to PlatformContextCairo's ctor:

void GraphicsContext::platformInit(HDC dc, bool hasAlpha)
{
    cairo_t* cr = 0;
    if (dc)
        cr = createCairoContextWithHDC(dc, hasAlpha);//cr is created with ref count of 1
    else
        setPaintingDisabled(true);    

    m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));//cr now has a ref count of 2 because of PlatformContextCairo RefPtr<cairo_t> m_cr;

    cairo_destroy(cr);//to prevent memory leak restore cr ref count to 1 so ~PlatformContextCairo will destroy with ref count of 1 

    m_data->m_hdc = dc;
    if (platformContext()->cr()) {
        // Make sure the context starts in sync with our state.
        setPlatformFillColor(fillColor(), fillColorSpace());
        setPlatformStrokeColor(strokeColor(), strokeColorSpace());
    }
}

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list