RESOLVED FIXED 76219
cairo_t* memory leak in GraphicsContext::platformInit
https://bugs.webkit.org/show_bug.cgi?id=76219
Summary cairo_t* memory leak in GraphicsContext::platformInit
Brian Stuart
Reported 2012-01-12 15:06:58 PST
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()); } }
Attachments
Proposal for fixing the memory leak in WinCairo (605 bytes, patch)
2012-10-17 00:21 PDT, Hideki
no flags
Proposal for fixing the memory leak in WinCairo (Revised patch) (520 bytes, patch)
2012-11-11 23:12 PST, Hideki
bfulgham: review-
Proposal for fixing the memory leak in WinCairo (Revised patch v2) (1.40 KB, patch)
2012-11-14 00:50 PST, Hideki
bfulgham: review+
bfulgham: commit-queue-
Hideki
Comment 1 2012-10-17 00:21:17 PDT
Created attachment 169104 [details] Proposal for fixing the memory leak in WinCairo Thank you for useful information, Brain. My team also found same memory leak problem in WinCairo port and figured out the same bug. Here is the patch which we made. We just moved cairo_destroy(cr); to the end of the function and added if statement to make sure that cr is not ZERO for fear that createCairoContextWithHDC is not called.
WebKit Review Bot
Comment 2 2012-11-05 18:59:50 PST
Attachment 169104 [details] did not pass style-queue: Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/platform/graphics/win/Graph..." exit_code: 1 Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp:91: More than one command on the same line in if [whitespace/parens] [4] Total errors found: 1 in 1 files If any of these errors are false positives, please file a bug against check-webkit-style.
Hideki
Comment 3 2012-11-11 23:12:18 PST
Created attachment 173567 [details] Proposal for fixing the memory leak in WinCairo (Revised patch) We revised the patch refering the comment sent by BOT. We just modified its format, no context of program has been changed. ------ Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/platform/graphics/win/Graph..." exit_code: 1 Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp:91: More than one command on the same line in if [whitespace/parens] [4] Total errors found: 1 in 1 files ------
Brent Fulgham
Comment 4 2012-11-13 09:20:20 PST
Comment on attachment 173567 [details] Proposal for fixing the memory leak in WinCairo (Revised patch) Nice catch. I think this patch is fine, though there is no ChangeLog entry. Please add a ChangeLog to the patch and I will be happy to approve it. r- because of the missing ChangeLog.
Hideki
Comment 5 2012-11-14 00:50:59 PST
Created attachment 174097 [details] Proposal for fixing the memory leak in WinCairo (Revised patch v2) Added ChangeLog.
Brent Fulgham
Comment 6 2012-11-14 09:29:15 PST
Comment on attachment 174097 [details] Proposal for fixing the memory leak in WinCairo (Revised patch v2) View in context: https://bugs.webkit.org/attachment.cgi?id=174097&action=review r = me; I will correct the URL ordering and land the change. > Source/WebCore/ChangeLog:3 > + https://bugs.webkit.org/show_bug.cgi?id=76219 We put the bug URL after the short description.
Brent Fulgham
Comment 7 2012-11-14 10:54:06 PST
Note You need to log in before you can comment on or make changes to this bug.