Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: runtime/vm/parser.cc

Issue 11806003: Fix context chaining to prevent memory leak (issue 7681). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 16755)
+++ runtime/vm/parser.cc (working copy)
@@ -186,17 +186,22 @@
scope,
&context_owner);
- // If this function is not a closure function and if it contains captured
- // variables, the context needs to be saved on entry and restored on exit.
+ // If this function allocates context variables, but none of its enclosing
+ // functions do, the context on entry is not linked as parent of the allocated
+ // context but saved on entry and restored on exit as to prevent memory leaks.
// Add and allocate a local variable to this purpose.
- if ((context_owner != NULL) && !function().IsClosureFunction()) {
- LocalVariable* context_var =
- new LocalVariable(function().token_pos(),
- Symbols::SavedEntryContextVar(),
- Type::ZoneHandle(Type::DynamicType()));
- context_var->set_index(next_free_frame_index--);
- scope->AddVariable(context_var);
- set_saved_context_var(context_var);
+ if (context_owner != NULL) {
+ const ContextScope& context_scope =
+ ContextScope::Handle(function().context_scope());
+ if (context_scope.IsNull() || (context_scope.num_variables() == 0)) {
+ LocalVariable* context_var =
+ new LocalVariable(function().token_pos(),
+ Symbols::SavedEntryContextVar(),
+ Type::ZoneHandle(Type::DynamicType()));
+ context_var->set_index(next_free_frame_index--);
+ scope->AddVariable(context_var);
+ set_saved_context_var(context_var);
+ }
}
// Frame indices are relative to the frame pointer and are decreasing.
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698