<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[204791] releases/WebKitGTK/webkit-2.12</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/204791">204791</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-23 02:57:31 -0700 (Tue, 23 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/201608">r201608</a> - Fix a couple of mistakes in CSSParserValue memory management
https://bugs.webkit.org/show_bug.cgi?id=158307
&lt;rdar://problem/26127225&gt;

Source/WebCore:

Patch by Darin Adler &lt;darin@apple.com&gt; on 2016-06-02
Reviewed by Daniel Bates.

* css/CSSGrammar.y.in: Added a destructor for calc_func_term. This presumably
fixes some memory leaks in error cases. Removed an assertion about not needing
a call to destroy that was far too limited. Tweaked formatting of the percentage
ase in the key production. Indented calc_func_term to make it consistent with
other productions nearby.

* css/CSSParserValues.cpp:
(WebCore::CSSParserValueList::~CSSParserValueList): Use a modern for loop.
(WebCore::CSSParserValueList::deleteValueAt): Deleted. Unused function, and also
would have resulted in a memory leak unless the code already extracted the value
from the list.
(WebCore::CSSParserValueList::extend): Properly transfer ownership from one value
list to the other by setting the unit to 0 in the donor.

* css/CSSParserValues.h: Removed unused deleteValueAt function.

LayoutTests:

Reviewed by Darin Adler.

* fast/css/calc-with-two-variables-crash-expected.txt: Added.
* fast/css/calc-with-two-variables-crash.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit212LayoutTestsChangeLog">releases/WebKitGTK/webkit-2.12/LayoutTests/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourceWebCoreChangeLog">releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourceWebCorecssCSSGrammaryin">releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSGrammar.y.in</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourceWebCorecssCSSParserValuescpp">releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourceWebCorecssCSSParserValuesh">releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit212LayoutTestsfastcsscalcwithtwovariablescrashexpectedtxt">releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt</a></li>
<li><a href="#releasesWebKitGTKwebkit212LayoutTestsfastcsscalcwithtwovariablescrashhtml">releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit212LayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/LayoutTests/ChangeLog (204790 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/LayoutTests/ChangeLog        2016-08-23 09:52:09 UTC (rev 204790)
+++ releases/WebKitGTK/webkit-2.12/LayoutTests/ChangeLog        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-06-02  Daniel Bates  &lt;dabates@apple.com&gt;
+
+        Fix a couple of mistakes in CSSParserValue memory management
+        https://bugs.webkit.org/show_bug.cgi?id=158307
+        &lt;rdar://problem/26127225&gt;
+
+        Reviewed by Darin Adler.
+
+        * fast/css/calc-with-two-variables-crash-expected.txt: Added.
+        * fast/css/calc-with-two-variables-crash.html: Added.
+
</ins><span class="cx"> 2016-06-13  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         SVG elements don't blend correctly into HTML
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212LayoutTestsfastcsscalcwithtwovariablescrashexpectedtxt"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt (0 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt                                (rev 0)
+++ releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+This test PASSED if it doesn't cause a crash, especially when run with Guard Malloc or MallocScribble enabled.
+
+
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit212LayoutTestsfastcsscalcwithtwovariablescrashhtml"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash.html (0 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash.html                                (rev 0)
+++ releases/WebKitGTK/webkit-2.12/LayoutTests/fast/css/calc-with-two-variables-crash.html        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script&gt;
+if (window.testRunner)
+    testRunner.dumpAsText();
+&lt;/script&gt;
+&lt;style&gt;
+#test {
+    --baseLength: 64px;
+    --scaleFactor: 2;
+    height: calc(var(--scaleFactor) * (var(--baseLength))); /* The extra parentheses around the second operand are necessary. */
+    width: 128px;
+    background-color: blue;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p&gt;This test PASSED if it doesn't cause a crash, especially when run with Guard Malloc or MallocScribble enabled.&lt;/p&gt;
+&lt;div id=&quot;test&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+// Iterating at least 100 times seems to reliably reproduce the crash when run without Guard Malloc/MallocScribble enabled.
+for (var i = 0; i &lt; 100; ++i) {
+    var oldStyleElement = document.querySelector(&quot;style&quot;);
+    var newStyleElement = document.createElement(&quot;style&quot;);
+    newStyleElement.textContent = oldStyleElement.textContent;
+    document.head.removeChild(oldStyleElement);
+    document.head.appendChild(newStyleElement);
+}
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog (204790 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog        2016-08-23 09:52:09 UTC (rev 204790)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/ChangeLog        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-06-02  Darin Adler  &lt;darin@apple.com&gt;
+
+        Fix a couple of mistakes in CSSParserValue memory management
+        https://bugs.webkit.org/show_bug.cgi?id=158307
+        &lt;rdar://problem/26127225&gt;
+
+        Reviewed by Daniel Bates.
+
+        * css/CSSGrammar.y.in: Added a destructor for calc_func_term. This presumably
+        fixes some memory leaks in error cases. Removed an assertion about not needing
+        a call to destroy that was far too limited. Tweaked formatting of the percentage
+        ase in the key production. Indented calc_func_term to make it consistent with
+        other productions nearby.
+
+        * css/CSSParserValues.cpp:
+        (WebCore::CSSParserValueList::~CSSParserValueList): Use a modern for loop.
+        (WebCore::CSSParserValueList::deleteValueAt): Deleted. Unused function, and also
+        would have resulted in a memory leak unless the code already extracted the value
+        from the list.
+        (WebCore::CSSParserValueList::extend): Properly transfer ownership from one value
+        list to the other by setting the unit to 0 in the donor.
+
+        * css/CSSParserValues.h: Removed unused deleteValueAt function.
+
</ins><span class="cx"> 2016-06-13  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         SVG elements don't blend correctly into HTML
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourceWebCorecssCSSGrammaryin"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSGrammar.y.in (204790 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSGrammar.y.in        2016-08-23 09:52:09 UTC (rev 204790)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSGrammar.y.in        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -294,12 +294,12 @@
</span><span class="cx"> %type &lt;keyframeRuleList&gt; keyframes_rule
</span><span class="cx"> %destructor { delete $$; } keyframes_rule
</span><span class="cx"> 
</span><del>-// These parser values never need to be destroyed because they are never functions or value lists.
-%type &lt;value&gt; calc_func_term key unary_term
</del><ins>+// These parser values never need to be destroyed because they are never functions, value lists, or variables.
+%type &lt;value&gt; key unary_term
</ins><span class="cx"> 
</span><del>-// These parser values need to be destroyed because they might be functions.
-%type &lt;value&gt; calc_function function variable_function min_or_max_function term
-%destructor { destroy($$); } calc_function function variable_function min_or_max_function term
</del><ins>+// These parser values need to be destroyed because they might be functions, value lists, or variables.
+%type &lt;value&gt; calc_func_term calc_function function min_or_max_function term variable_function
+%destructor { destroy($$); } calc_func_term calc_function function min_or_max_function term variable_function
</ins><span class="cx"> 
</span><span class="cx"> %type &lt;id&gt; property
</span><span class="cx"> 
</span><span class="lines">@@ -823,7 +823,6 @@
</span><span class="cx">     }
</span><span class="cx">     | key_list maybe_space ',' maybe_space key {
</span><span class="cx">         $$ = $1;
</span><del>-        ASSERT($5.unit != CSSParserValue::Function); // No need to call destroy.
</del><span class="cx">         if ($$)
</span><span class="cx">             $$-&gt;addValue($5);
</span><span class="cx">     }
</span><span class="lines">@@ -830,7 +829,12 @@
</span><span class="cx">     ;
</span><span class="cx"> 
</span><span class="cx"> key:
</span><del>-    maybe_unary_operator PERCENTAGE { $$.id = CSSValueInvalid; $$.isInt = false; $$.fValue = $1 * $2; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
</del><ins>+    maybe_unary_operator PERCENTAGE {
+        $$.id = CSSValueInvalid;
+        $$.isInt = false;
+        $$.fValue = $1 * $2;
+        $$.unit = CSSPrimitiveValue::CSS_NUMBER;
+    }
</ins><span class="cx">     | IDENT {
</span><span class="cx">         $$.id = CSSValueInvalid;
</span><span class="cx">         $$.isInt = false;
</span><span class="lines">@@ -1838,10 +1842,10 @@
</span><span class="cx">     '!' | ';';
</span><span class="cx"> 
</span><span class="cx"> calc_func_term:
</span><del>-  unary_term
-  | variable_function { $$ = $1; }
-  | unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
-  ;
</del><ins>+    unary_term
+    | unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
+    | variable_function
+    ;
</ins><span class="cx"> 
</span><span class="cx"> /*
</span><span class="cx">  * The grammar requires spaces around binary ‘+’ and ‘-’ operators.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourceWebCorecssCSSParserValuescpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.cpp (204790 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.cpp        2016-08-23 09:52:09 UTC (rev 204790)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.cpp        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -46,31 +46,28 @@
</span><span class="cx"> 
</span><span class="cx"> CSSParserValueList::~CSSParserValueList()
</span><span class="cx"> {
</span><del>-    for (size_t i = 0, size = m_values.size(); i &lt; size; i++)
-        destroy(m_values[i]);
</del><ins>+    for (auto&amp; value : m_values)
+        destroy(value);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSParserValueList::addValue(const CSSParserValue&amp; v)
</del><ins>+void CSSParserValueList::addValue(const CSSParserValue&amp; value)
</ins><span class="cx"> {
</span><del>-    m_values.append(v);
</del><ins>+    m_values.append(value);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSParserValueList::insertValueAt(unsigned i, const CSSParserValue&amp; v)
</del><ins>+void CSSParserValueList::insertValueAt(unsigned i, const CSSParserValue&amp; value)
</ins><span class="cx"> {
</span><del>-    m_values.insert(i, v);
</del><ins>+    m_values.insert(i, value);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSParserValueList::deleteValueAt(unsigned i)
</del><ins>+void CSSParserValueList::extend(CSSParserValueList&amp; other)
</ins><span class="cx"> {
</span><del>-    m_values.remove(i);
</del><ins>+    for (auto&amp; value : other.m_values) {
+        m_values.append(value);
+        value.unit = 0; // We moved the CSSParserValue from the other list; this acts like std::move.
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSParserValueList::extend(CSSParserValueList&amp; valueList)
-{
-    for (unsigned int i = 0; i &lt; valueList.size(); ++i)
-        m_values.append(*(valueList.valueAt(i)));
-}
-
</del><span class="cx"> bool CSSParserValueList::containsVariables() const
</span><span class="cx"> {
</span><span class="cx">     for (unsigned i = 0; i &lt; size(); i++) {
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourceWebCorecssCSSParserValuesh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.h (204790 => 204791)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.h        2016-08-23 09:52:09 UTC (rev 204790)
+++ releases/WebKitGTK/webkit-2.12/Source/WebCore/css/CSSParserValues.h        2016-08-23 09:57:31 UTC (rev 204791)
</span><span class="lines">@@ -18,8 +18,7 @@
</span><span class="cx">  * Boston, MA 02110-1301, USA.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef CSSParserValues_h
-#define CSSParserValues_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include &quot;CSSSelector.h&quot;
</span><span class="cx"> #include &quot;CSSValueKeywords.h&quot;
</span><span class="lines">@@ -140,7 +139,6 @@
</span><span class="cx"> 
</span><span class="cx">     void addValue(const CSSParserValue&amp;);
</span><span class="cx">     void insertValueAt(unsigned, const CSSParserValue&amp;);
</span><del>-    void deleteValueAt(unsigned);
</del><span class="cx">     void extend(CSSParserValueList&amp;);
</span><span class="cx"> 
</span><span class="cx">     unsigned size() const { return m_values.size(); }
</span><span class="lines">@@ -274,5 +272,3 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span><del>-
-#endif
</del></span></pre>
</div>
</div>

</body>
</html>