<!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>[201608] trunk</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/201608">201608</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-06-02 12:05:40 -0700 (Thu, 02 Jun 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix a couple of mistakes in CSSParserValue memory management
https://bugs.webkit.org/show_bug.cgi?id=158307
<rdar://problem/26127225>
Source/WebCore:
Patch by Darin Adler <darin@apple.com> 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="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSGrammaryin">trunk/Source/WebCore/css/CSSGrammar.y.in</a></li>
<li><a href="#trunkSourceWebCorecssCSSParserValuescpp">trunk/Source/WebCore/css/CSSParserValues.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSParserValuesh">trunk/Source/WebCore/css/CSSParserValues.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastcsscalcwithtwovariablescrashexpectedtxt">trunk/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcsscalcwithtwovariablescrashhtml">trunk/LayoutTests/fast/css/calc-with-two-variables-crash.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (201607 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-06-02 19:04:51 UTC (rev 201607)
+++ trunk/LayoutTests/ChangeLog        2016-06-02 19:05:40 UTC (rev 201608)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-06-02 Daniel Bates <dabates@apple.com>
+
+ Fix a couple of mistakes in CSSParserValue memory management
+ https://bugs.webkit.org/show_bug.cgi?id=158307
+ <rdar://problem/26127225>
+
+ 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-02 Said Abou-Hallawa <sabouhallawa@apple.com>
</span><span class="cx">
</span><span class="cx"> SVG content renders in incorrect vertical position when padding-left is not specified
</span></span></pre></div>
<a id="trunkLayoutTestsfastcsscalcwithtwovariablescrashexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt (0 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/css/calc-with-two-variables-crash-expected.txt        2016-06-02 19:05:40 UTC (rev 201608)
</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="trunkLayoutTestsfastcsscalcwithtwovariablescrashhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css/calc-with-two-variables-crash.html (0 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css/calc-with-two-variables-crash.html         (rev 0)
+++ trunk/LayoutTests/fast/css/calc-with-two-variables-crash.html        2016-06-02 19:05:40 UTC (rev 201608)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+<style>
+#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;
+}
+</style>
+</head>
+<body>
+<p>This test PASSED if it doesn't cause a crash, especially when run with Guard Malloc or MallocScribble enabled.</p>
+<div id="test"></div>
+<script>
+// Iterating at least 100 times seems to reliably reproduce the crash when run without Guard Malloc/MallocScribble enabled.
+for (var i = 0; i < 100; ++i) {
+ var oldStyleElement = document.querySelector("style");
+ var newStyleElement = document.createElement("style");
+ newStyleElement.textContent = oldStyleElement.textContent;
+ document.head.removeChild(oldStyleElement);
+ document.head.appendChild(newStyleElement);
+}
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201607 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-06-02 19:04:51 UTC (rev 201607)
+++ trunk/Source/WebCore/ChangeLog        2016-06-02 19:05:40 UTC (rev 201608)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-06-02 Darin Adler <darin@apple.com>
+
+ Fix a couple of mistakes in CSSParserValue memory management
+ https://bugs.webkit.org/show_bug.cgi?id=158307
+ <rdar://problem/26127225>
+
+ 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-02 Said Abou-Hallawa <sabouhallawa@apple.com>
</span><span class="cx">
</span><span class="cx"> SVG content renders in incorrect vertical position when padding-left is not specified
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSGrammaryin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (201607 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSGrammar.y.in        2016-06-02 19:04:51 UTC (rev 201607)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in        2016-06-02 19:05:40 UTC (rev 201608)
</span><span class="lines">@@ -294,12 +294,12 @@
</span><span class="cx"> %type <keyframeRuleList> 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 <value> 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 <value> key unary_term
</ins><span class="cx">
</span><del>-// These parser values need to be destroyed because they might be functions.
-%type <value> 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 <value> 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 <id> property
</span><span class="cx">
</span><span class="lines">@@ -837,14 +837,18 @@
</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"> $$->addValue($5);
</span><span class="cx"> }
</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">@@ -1860,10 +1864,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="trunkSourceWebCorecssCSSParserValuescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParserValues.cpp (201607 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParserValues.cpp        2016-06-02 19:04:51 UTC (rev 201607)
+++ trunk/Source/WebCore/css/CSSParserValues.cpp        2016-06-02 19:05:40 UTC (rev 201608)
</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 < size; i++)
- destroy(m_values[i]);
</del><ins>+ for (auto& value : m_values)
+ destroy(value);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void CSSParserValueList::addValue(const CSSParserValue& v)
</del><ins>+void CSSParserValueList::addValue(const CSSParserValue& 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& v)
</del><ins>+void CSSParserValueList::insertValueAt(unsigned i, const CSSParserValue& 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& other)
</ins><span class="cx"> {
</span><del>- m_values.remove(i);
</del><ins>+ for (auto& 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& valueList)
-{
- for (unsigned int i = 0; i < 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 < size(); i++) {
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParserValuesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParserValues.h (201607 => 201608)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParserValues.h        2016-06-02 19:04:51 UTC (rev 201607)
+++ trunk/Source/WebCore/css/CSSParserValues.h        2016-06-02 19:05:40 UTC (rev 201608)
</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 "CSSSelector.h"
</span><span class="cx"> #include "CSSValueKeywords.h"
</span><span class="lines">@@ -140,7 +139,6 @@
</span><span class="cx">
</span><span class="cx"> void addValue(const CSSParserValue&);
</span><span class="cx"> void insertValueAt(unsigned, const CSSParserValue&);
</span><del>- void deleteValueAt(unsigned);
</del><span class="cx"> void extend(CSSParserValueList&);
</span><span class="cx">
</span><span class="cx"> unsigned size() const { return m_values.size(); }
</span><span class="lines">@@ -278,5 +276,3 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> }
</span><del>-
-#endif
</del></span></pre>
</div>
</div>
</body>
</html>