<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>76219</bug_id>
          
          <creation_ts>2012-01-12 15:06:58 -0800</creation_ts>
          <short_desc>cairo_t* memory leak in GraphicsContext::platformInit</short_desc>
          <delta_ts>2012-11-14 10:54:06 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 7</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://smithmicro.com</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Brian Stuart">bstuart</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>dbates</cc>
    
    <cc>hirano-txb</cc>
    
    <cc>mrobinson</cc>
    
    <cc>webkit.review.bot</cc>
    
    <cc>yoshida-hxa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>535207</commentid>
    <comment_count>0</comment_count>
    <who name="Brian Stuart">bstuart</who>
    <bug_when>2012-01-12 15:06:58 -0800</bug_when>
    <thetext>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&apos;s ctor causes the reference count to increment to 2. Now when ~PlatformContextCairo is called it&apos;s cairo_t* is leaked.

Here is my workaround, a better solution would involve using adoptRef and passing a RefPtr to PlatformContextCairo&apos;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&lt;cairo_t&gt; 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-&gt;m_hdc = dc;
    if (platformContext()-&gt;cr()) {
        // Make sure the context starts in sync with our state.
        setPlatformFillColor(fillColor(), fillColorSpace());
        setPlatformStrokeColor(strokeColor(), strokeColorSpace());
    }
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>743944</commentid>
    <comment_count>1</comment_count>
      <attachid>169104</attachid>
    <who name="Hideki">yoshida-hxa</who>
    <bug_when>2012-10-17 00:21:17 -0700</bug_when>
    <thetext>Created attachment 169104
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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>759157</commentid>
    <comment_count>2</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-11-05 18:59:50 -0800</bug_when>
    <thetext>Attachment 169104 did not pass style-queue:

Failed to run &quot;[&apos;Tools/Scripts/check-webkit-style&apos;, &apos;--diff-files&apos;, u&apos;Source/WebCore/platform/graphics/win/Graph...&quot; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>764084</commentid>
    <comment_count>3</comment_count>
      <attachid>173567</attachid>
    <who name="Hideki">yoshida-hxa</who>
    <bug_when>2012-11-11 23:12:18 -0800</bug_when>
    <thetext>Created attachment 173567
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 &quot;[&apos;Tools/Scripts/check-webkit-style&apos;, &apos;--diff-files&apos;, u&apos;Source/WebCore/platform/graphics/win/Graph...&quot; 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
------</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>765684</commentid>
    <comment_count>4</comment_count>
      <attachid>173567</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2012-11-13 09:20:20 -0800</bug_when>
    <thetext>Comment on attachment 173567
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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>766572</commentid>
    <comment_count>5</comment_count>
      <attachid>174097</attachid>
    <who name="Hideki">yoshida-hxa</who>
    <bug_when>2012-11-14 00:50:59 -0800</bug_when>
    <thetext>Created attachment 174097
Proposal for fixing the memory leak in WinCairo (Revised patch v2)

Added ChangeLog.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>766969</commentid>
    <comment_count>6</comment_count>
      <attachid>174097</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2012-11-14 09:29:15 -0800</bug_when>
    <thetext>Comment on attachment 174097
Proposal for fixing the memory leak in WinCairo (Revised patch v2)

View in context: https://bugs.webkit.org/attachment.cgi?id=174097&amp;action=review

r = me; I will correct the URL ordering and land the change.

&gt; Source/WebCore/ChangeLog:3
&gt; +        https://bugs.webkit.org/show_bug.cgi?id=76219

We put the bug URL after the short description.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>767056</commentid>
    <comment_count>7</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2012-11-14 10:54:06 -0800</bug_when>
    <thetext>Committed r134629: &lt;http://trac.webkit.org/changeset/134629&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>169104</attachid>
            <date>2012-10-17 00:21:17 -0700</date>
            <delta_ts>2012-11-11 23:13:25 -0800</delta_ts>
            <desc>Proposal for fixing the memory leak in WinCairo</desc>
            <filename>diff.txt</filename>
            <type>text/plain</type>
            <size>605</size>
            <attacher name="Hideki">yoshida-hxa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL3BsYXRmb3JtL2dyYXBoaWNzL3dpbi9HcmFwaGljc0NvbnRl
eHRDYWlyb1dpbi5jcHANCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT0NCi0tLSBTb3VyY2UvV2ViQ29yZS9wbGF0Zm9ybS9n
cmFwaGljcy93aW4vR3JhcGhpY3NDb250ZXh0Q2Fpcm9XaW4uY3BwCShyZXZpc2lvbiAxMzExMDkp
DQorKysgU291cmNlL1dlYkNvcmUvcGxhdGZvcm0vZ3JhcGhpY3Mvd2luL0dyYXBoaWNzQ29udGV4
dENhaXJvV2luLmNwcAkod29ya2luZyBjb3B5KQ0KQEAgLTg4LDYgKzg4LDcgQEANCiAgICAgICAg
IHNldFBsYXRmb3JtRmlsbENvbG9yKGZpbGxDb2xvcigpLCBmaWxsQ29sb3JTcGFjZSgpKTsNCiAg
ICAgICAgIHNldFBsYXRmb3JtU3Ryb2tlQ29sb3Ioc3Ryb2tlQ29sb3IoKSwgc3Ryb2tlQ29sb3JT
cGFjZSgpKTsNCiAgICAgfQ0KKyAgICBpZiAoY3IpIGNhaXJvX2Rlc3Ryb3koY3IpOw0KIH0NCiAN
CiBzdGF0aWMgdm9pZCBzZXRSR0JBQml0bWFwQWxwaGEodW5zaWduZWQgY2hhciogYnl0ZXMsIHNp
emVfdCBsZW5ndGgsIHVuc2lnbmVkIGNoYXIgbGV2ZWwpDQo=
</data>

          </attachment>
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>173567</attachid>
            <date>2012-11-11 23:12:18 -0800</date>
            <delta_ts>2012-11-14 00:48:45 -0800</delta_ts>
            <desc>Proposal for fixing the memory leak in WinCairo (Revised patch)</desc>
            <filename>diff2.txt</filename>
            <type>text/plain</type>
            <size>520</size>
            <attacher name="Hideki">yoshida-hxa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL3BsYXRmb3JtL2dyYXBoaWNzL3dpbi9HcmFwaGljc0NvbnRl
eHRDYWlyb1dpbi5jcHAKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291cmNlL1dlYkNvcmUvcGxhdGZvcm0vZ3Jh
cGhpY3Mvd2luL0dyYXBoaWNzQ29udGV4dENhaXJvV2luLmNwcAkocmV2aXNpb24gMTM0MTc0KQor
KysgU291cmNlL1dlYkNvcmUvcGxhdGZvcm0vZ3JhcGhpY3Mvd2luL0dyYXBoaWNzQ29udGV4dENh
aXJvV2luLmNwcAkod29ya2luZyBjb3B5KQpAQCAtODgsNiArODgsOCBAQAogICAgICAgICBzZXRQ
bGF0Zm9ybUZpbGxDb2xvcihmaWxsQ29sb3IoKSwgZmlsbENvbG9yU3BhY2UoKSk7CiAgICAgICAg
IHNldFBsYXRmb3JtU3Ryb2tlQ29sb3Ioc3Ryb2tlQ29sb3IoKSwgc3Ryb2tlQ29sb3JTcGFjZSgp
KTsKICAgICB9CisgICAgaWYgKGNyKQorICAgICAgICBjYWlyb19kZXN0cm95KGNyKTsKIH0KICNl
bmRpZgogCg==
</data>
<flag name="review"
          id="188300"
          type_id="1"
          status="-"
          setter="bfulgham"
    />
          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>174097</attachid>
            <date>2012-11-14 00:50:59 -0800</date>
            <delta_ts>2012-11-14 09:29:15 -0800</delta_ts>
            <desc>Proposal for fixing the memory leak in WinCairo (Revised patch v2)</desc>
            <filename>diff3.txt</filename>
            <type>text/plain</type>
            <size>1438</size>
            <attacher name="Hideki">yoshida-hxa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDEzNDU0MikKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE4IEBACisyMDEyLTExLTE0ICBIaWRla2kg
WW9zaGlkYSAgPHlvc2hpZGEtaHhhQG5lY3N0Lm5lYy5jby5qcD4KKworICAgICAgICBodHRwczov
L2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9NzYyMTkKKyAgICAgICAgRml4IGNhaXJv
X3QqIG1lbW9yeSBsZWFrIGluIEdyYXBoaWNzQ29udGV4dDo6cGxhdGZvcm1Jbml0CisKKyAgICAg
ICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgVGhpcyBwYXRjaCBpcyB0
byBmaXggYSBtZW1vcnkgbGVhayBwcm9ibGVtIHdoaWNoIG9jY3VycworICAgICAgICBpbiBldmVy
eSByZW5kZXJpbmcgcHJvY2VzcyBvbiBXaW5jYWlybyBwb3J0LgorICAgICAgICBCeSBhcHBseWlu
ZyB0aGl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B9CisgICAgaWYgKGNyKQorICAgICAgICBjYWlyb19kZXN0cm95KGNyKTsK
IH0KICNlbmRpZgogCg==
</data>
<flag name="review"
          id="189023"
          type_id="1"
          status="+"
          setter="bfulgham"
    />
    <flag name="commit-queue"
          id="189024"
          type_id="3"
          status="-"
          setter="bfulgham"
    />
          </attachment>
      

    </bug>

</bugzilla>