Skip to content

Commit 200ae6c

Browse files
committed
Fix memory leak by removing previously unused code
Ensure to take over returned ast node. Skip CRTP operator for parent selectors.
1 parent 8ea0ad8 commit 200ae6c

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/eval.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ namespace Sass {
17671767
Complex_Selector_Ptr is = resolved->at(i)->first();
17681768
while (is) {
17691769
if (is->head()) {
1770-
is->head()->perform(this);
1770+
is->head(operator()(is->head()));
17711771
}
17721772
is = is->tail();
17731773
}
@@ -1779,21 +1779,13 @@ namespace Sass {
17791779
{
17801780
for (size_t i = 0; i < s->length(); i++) {
17811781
Simple_Selector_Ptr ss = s->at(i);
1782-
if (ss) ss->perform(this);
1782+
// skip parents here (called via resolve_parent_refs)
1783+
if (ss == NULL || Cast<Parent_Selector>(ss)) continue;
1784+
s->at(i) = Cast<Simple_Selector>(ss->perform(this));
17831785
}
17841786
return s;
17851787
}
17861788

1787-
// XXX: this is never hit via spec tests
1788-
Attribute_Selector_Ptr Eval::operator()(Attribute_Selector_Ptr s)
1789-
{
1790-
String_Obj attr = s->value();
1791-
if (attr) { attr = static_cast<String_Ptr>(attr->perform(this)); }
1792-
Attribute_Selector_Ptr ss = SASS_MEMORY_COPY(s);
1793-
ss->value(attr);
1794-
return ss;
1795-
}
1796-
17971789
Selector_List_Ptr Eval::operator()(Selector_Schema_Ptr s)
17981790
{
17991791
LOCAL_FLAG(is_in_selector_schema, true);
@@ -1841,6 +1833,11 @@ namespace Sass {
18411833
}
18421834
}
18431835

1836+
Simple_Selector_Ptr Eval::operator()(Simple_Selector_Ptr s)
1837+
{
1838+
return s;
1839+
}
1840+
18441841
// hotfix to avoid invalid nested `:not` selectors
18451842
// probably the wrong place, but this should ultimately
18461843
// be fixed by implement superselector correctly for `:not`
@@ -1872,7 +1869,6 @@ namespace Sass {
18721869
}
18731870
}
18741871
}
1875-
18761872
return s;
18771873
};
18781874

src/eval.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ namespace Sass {
7676
Selector_List_Ptr operator()(Selector_List_Ptr);
7777
Selector_List_Ptr operator()(Complex_Selector_Ptr);
7878
Compound_Selector_Ptr operator()(Compound_Selector_Ptr);
79-
Attribute_Selector_Ptr operator()(Attribute_Selector_Ptr);
80-
// they don't have any specific implementatio (yet)
81-
Element_Selector_Ptr operator()(Element_Selector_Ptr s) { return s; };
82-
Pseudo_Selector_Ptr operator()(Pseudo_Selector_Ptr s) { return s; };
79+
Simple_Selector_Ptr operator()(Simple_Selector_Ptr s);
8380
Wrapped_Selector_Ptr operator()(Wrapped_Selector_Ptr s);
84-
Class_Selector_Ptr operator()(Class_Selector_Ptr s) { return s; };
85-
Id_Selector_Ptr operator()(Id_Selector_Ptr s) { return s; };
86-
Placeholder_Selector_Ptr operator()(Placeholder_Selector_Ptr s) { return s; };
81+
// they don't have any specific implementation (yet)
82+
// Element_Selector_Ptr operator()(Element_Selector_Ptr s) { return s; };
83+
// Pseudo_Selector_Ptr operator()(Pseudo_Selector_Ptr s) { return s; };
84+
// Class_Selector_Ptr operator()(Class_Selector_Ptr s) { return s; };
85+
// Id_Selector_Ptr operator()(Id_Selector_Ptr s) { return s; };
86+
// Placeholder_Selector_Ptr operator()(Placeholder_Selector_Ptr s) { return s; };
8787
// actual evaluated selectors
8888
Selector_List_Ptr operator()(Selector_Schema_Ptr);
8989
Expression_Ptr operator()(Parent_Selector_Ptr);

0 commit comments

Comments
 (0)