Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few minor memory leaks #2400

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
The following is a set of guidelines for contributing to LibSass, which is hosted in the [Sass Organization](https://github.com/sass) on GitHub.
These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.

LibSass is a library that implements a [sass language] [8] compiler. As such it does not directly interface with end users (frontend developers).
LibSass is a library that implements a [sass language][8] compiler. As such it does not directly interface with end users (frontend developers).
For direct contributions to the LibSass code base you will need to have at least a rough idea of C++, we will not lie about that.
But there are other ways to contribute to the progress of LibSass. All contributions are done via github pull requests.

You can also contribute to the LibSass [documentation] [9] or provide additional [spec tests] [10] (and we will gladly point you in the
You can also contribute to the LibSass [documentation][9] or provide additional [spec tests][10] (and we will gladly point you in the
direction for corners that lack test coverage). Foremost we rely on good and concise bug reports for issues the spec tests do not yet catch.

## Precheck: My Sass isn't compiling
- [ ] Check if you can reproduce the issue via [SourceMap Inspector] [5] (updated regularly).
- [ ] Validate official ruby sass compiler via [SassMeister] [6] produces your expected result.
- [ ] Search for similar issue in [LibSass] [1] and [node-sass] [2] (include closed tickets)
- [ ] Optionally test your code directly with [sass] [7] or [sassc] [3] ([installer] [4])
- [ ] Check if you can reproduce the issue via [SourceMap Inspector][5] (updated regularly).
- [ ] Validate official ruby sass compiler via [SassMeister][6] produces your expected result.
- [ ] Search for similar issue in [LibSass][1] and [node-sass][2] (include closed tickets)
- [ ] Optionally test your code directly with [sass][7] or [sassc][3] ([installer][4])

## Precheck: My build/install fails
- [ ] Problems with building or installing libsass should be directed to implementors first!
Expand Down Expand Up @@ -47,7 +47,7 @@ direction for corners that lack test coverage). Foremost we rely on good and con
## What makes a code test case

Important is that someone else can get the test case up and running to reproduce it locally. For this
we urge you to verify that your sample yields the expected result by testing it via [SassMeister] [6]
we urge you to verify that your sample yields the expected result by testing it via [SassMeister][6]
or directly via ruby sass or node-sass (or any other libsass implementor) before submitting your bug
report. Once you verified all of the above, you may use the template below to file your bug report.

Expand Down
37 changes: 31 additions & 6 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
### Title: Be as meaningful as possible in 60 chars if possible
[todo]: # (Title: Be as meaningful as possible)
[todo]: # (Title: Try to use 60 or less chars)

[todo]: # (This is only a template!)
[todo]: # (remove unneeded bits)
[todo]: # (use github preview!)

## input.scss

[todo]: # (always test and report with scss syntax)
[todo]: # (use sass only when results differ from scss)

input.scss
```scss
test {
content: bar
}
```

[libsass 3.5.5] [1]
## Actual results

[todo]: # (update version info!)

[libsass 3.X.y][1]
```css
test {
content: bar; }
```

ruby sass 3.4.21
## Expected result

[todo]: # (update version info!)

ruby sass 3.X.y
```css
test {
content: bar; }
```

[todo]: # (update version info!)
[todo]: # (example for node-sass!)

version info:
```cmd
$ node-sass --version
node-sass 3.3.3 (Wrapper) [JavaScript]
libsass 3.2.5 (Sass Compiler) [C/C++]
node-sass 3.X.y (Wrapper) [JavaScript]
libsass 3.X.y (Sass Compiler) [C/C++]
```

[todo]: # (Go to http://libsass.ocbnet.ch/srcmap)
[todo]: # (Enter your SCSS code and hit compile)
[todo]: # (Click `bookmark` and replace the url)
[todo]: # (link is used in actual results above)

[1]: http://libsass.ocbnet.ch/srcmap/#dGVzdCB7CiAgY29udGVudDogYmFyOyB9Cg==
1 change: 1 addition & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace Sass {
plugins(),
emitter(c_options),

ast_gc(),
strings(),
resources(),
sheets(),
Expand Down
3 changes: 3 additions & 0 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace Sass {
Plugins plugins;
Output emitter;

// generic ast node garbage container
// used to avoid possible circular refs
std::vector<AST_Node_Obj> ast_gc;
// resources add under our control
// these are guaranteed to be freed
std::vector<char*> strings;
Expand Down
8 changes: 7 additions & 1 deletion src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ namespace Sass {

Statement_Ptr Expand::operator()(Media_Block_Ptr m)
{
Media_Block_Ptr cpy = m->copy();
Media_Block_Obj cpy = SASS_MEMORY_COPY(m);
// Media_Blocks are prone to have circular references
// Copy could leak memory if it does not get picked up
// Looks like we are able to reset block reference for copy
// Good as it will ensure a low memory overhead for this fix
// So this is a cheap solution with a minimal price
ctx.ast_gc.push_back(cpy); cpy->block(0);
Expression_Obj mq = eval(m->media_queries());
std::string str_mq(mq->to_string(ctx.c_options));
char* str = sass_copy_c_string(str_mq.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/memory/SharedPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Sass {
std::cerr << "###################################\n";
std::cerr << "# REPORTING MISSING DEALLOCATIONS #\n";
std::cerr << "###################################\n";
for (auto var : all) {
if (AST_Node_Ptr ast = Cast<AST_Node>(var)) {
for (SharedObj* var : all) {
if (AST_Node_Ptr ast = dynamic_cast<AST_Node*>(var)) {
debug_ast(ast);
} else {
std::cerr << "LEAKED " << var << "\n";
Expand Down Expand Up @@ -60,7 +60,7 @@ namespace Sass {
#endif
if (node->refcounter == 0) {
#ifdef DEBUG_SHARED_PTR
AST_Node_Ptr ptr = Cast<AST_Node>(node);
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
#endif
if (!node->detached) {
Expand Down
2 changes: 1 addition & 1 deletion src/memory/SharedPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Sass {
#ifdef DEBUG_SHARED_PTR

#define SASS_MEMORY_NEW(Class, ...) \
((new Class(__VA_ARGS__))->trace(__FILE__, __LINE__)) \
((Class*)(new Class(__VA_ARGS__))->trace(__FILE__, __LINE__)) \

#define SASS_MEMORY_COPY(obj) \
((obj)->copy(__FILE__, __LINE__)) \
Expand Down
8 changes: 4 additions & 4 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ namespace Sass {
// selector schema re-uses string schema implementation
String_Schema_Ptr schema = SASS_MEMORY_NEW(String_Schema, pstate);
// the selector schema is pretty much just a wrapper for the string schema
Selector_Schema_Ptr selector_schema = SASS_MEMORY_NEW(Selector_Schema, pstate, schema);
Selector_Schema_Obj selector_schema = SASS_MEMORY_NEW(Selector_Schema, pstate, schema);
selector_schema->connect_parent(chroot == false);
selector_schema->media_block(last_media_block);

Expand Down Expand Up @@ -605,7 +605,7 @@ namespace Sass {
after_token = before_token = pstate;

// return parsed result
return selector_schema;
return selector_schema.detach();
}
// EO parse_selector_schema

Expand Down Expand Up @@ -1668,7 +1668,7 @@ namespace Sass {
return str_quoted;
}

String_Schema_Ptr schema = SASS_MEMORY_NEW(String_Schema, pstate);
String_Schema_Obj schema = SASS_MEMORY_NEW(String_Schema, pstate);
schema->is_interpolant(true);
while (i < chunk.end) {
p = constant ? find_first_in_interval< exactly<hash_lbrace> >(i, chunk.end) :
Expand Down Expand Up @@ -1704,7 +1704,7 @@ namespace Sass {
++ i;
}

return schema;
return schema.detach();
}

String_Constant_Obj Parser::parse_static_value()
Expand Down