Skip to content

Commit b68bc34

Browse files
committed
Try to fix memory leak
1 parent 2096899 commit b68bc34

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/ast_values.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,14 @@ namespace Sass {
11141114
// Implement delayed value fetcher
11151115
/////////////////////////////////////////////////////////////////////////
11161116

1117+
// The original value may not be returned
1118+
// Therefore make sure original is collected
11171119
Value* Number::withoutSlash()
11181120
{
11191121
if (!hasAsSlash()) return this;
11201122
// we are the only holder of this item
11211123
// therefore should be safe to alter it
1122-
if (this->refcount == 1) {
1124+
if (this->refcount <= 1) {
11231125
lhsAsSlash_.clear();
11241126
rhsAsSlash_.clear();
11251127
return this;

src/eval.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,18 @@ namespace Sass {
8383
/////////////////////////////////////////////////////////////////////////
8484
/////////////////////////////////////////////////////////////////////////
8585

86-
Value* Eval::withoutSlash(Value* value) {
86+
Value* Eval::withoutSlash(ValueObj value) {
87+
if (value == nullptr) return value;
8788
Number* number = value->isaNumber();
8889
if (number && number->hasAsSlash()) {
8990
logger.addDeprecation("Using / for division is deprecated and will be removed "
9091
"in LibSass 4.1.0.\n\nRecommendation: math.div(" + number->lhsAsSlash()->inspect() +
9192
", " + number->rhsAsSlash()->inspect() + ")\n\nMore info and automated migrator: "
9293
"https://sass-lang.com/d/slash-div", value->pstate());
9394
}
94-
return value->withoutSlash();
95+
// Make sure to collect all memory
96+
ValueObj result = value->withoutSlash();
97+
return result.detach();
9598
}
9699

97100
/////////////////////////////////////////////////////////////////////////
@@ -284,7 +287,7 @@ namespace Sass {
284287

285288
}
286289

287-
for (auto& arg : positional) {
290+
for (ValueObj& arg : positional) {
288291
arg = withoutSlash(arg);
289292
}
290293

src/eval.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Sass {
2828
void exposeFwdRule(ForwardRule* rule);
2929
void exposeImpRule(IncludeImport* rule);
3030

31-
Value* withoutSlash(Value* value);
31+
Value* withoutSlash(ValueObj value);
3232

3333
// Some references
3434
Logger& logger;

0 commit comments

Comments
 (0)