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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Allocate parameters and local variables, either in the local frame or 179 // Allocate parameters and local variables, either in the local frame or
180 // in the context(s). 180 // in the context(s).
181 LocalScope* context_owner = NULL; // No context needed yet. 181 LocalScope* context_owner = NULL; // No context needed yet.
182 int next_free_frame_index = 182 int next_free_frame_index =
183 scope->AllocateVariables(first_parameter_index_, 183 scope->AllocateVariables(first_parameter_index_,
184 num_params, 184 num_params,
185 first_stack_local_index_, 185 first_stack_local_index_,
186 scope, 186 scope,
187 &context_owner); 187 &context_owner);
188 188
189 // If this function is not a closure function and if it contains captured 189 // If this function allocates context variables, but none of its enclosing
190 // variables, the context needs to be saved on entry and restored on exit. 190 // functions do, the context on entry is not linked as parent of the allocated
191 // context but saved on entry and restored on exit as to prevent memory leaks.
Ivan Posva 2013/01/07 22:19:11 Please update the bug, but do not close it as we s
regis 2013/01/07 22:24:01 Done.
191 // Add and allocate a local variable to this purpose. 192 // Add and allocate a local variable to this purpose.
192 if ((context_owner != NULL) && !function().IsClosureFunction()) { 193 if (context_owner != NULL) {
193 LocalVariable* context_var = 194 const ContextScope& context_scope =
194 new LocalVariable(function().token_pos(), 195 ContextScope::Handle(function().context_scope());
195 Symbols::SavedEntryContextVar(), 196 if (context_scope.IsNull() || (context_scope.num_variables() == 0)) {
196 Type::ZoneHandle(Type::DynamicType())); 197 LocalVariable* context_var =
197 context_var->set_index(next_free_frame_index--); 198 new LocalVariable(function().token_pos(),
198 scope->AddVariable(context_var); 199 Symbols::SavedEntryContextVar(),
199 set_saved_context_var(context_var); 200 Type::ZoneHandle(Type::DynamicType()));
201 context_var->set_index(next_free_frame_index--);
202 scope->AddVariable(context_var);
203 set_saved_context_var(context_var);
204 }
200 } 205 }
201 206
202 // Frame indices are relative to the frame pointer and are decreasing. 207 // Frame indices are relative to the frame pointer and are decreasing.
203 ASSERT(next_free_frame_index <= first_stack_local_index_); 208 ASSERT(next_free_frame_index <= first_stack_local_index_);
204 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; 209 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index;
205 } 210 }
206 211
207 212
208 struct Parser::Block : public ZoneAllocated { 213 struct Parser::Block : public ZoneAllocated {
209 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) 214 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq)
(...skipping 9492 matching lines...) Expand 10 before | Expand all | Expand 10 after
9702 void Parser::SkipQualIdent() { 9707 void Parser::SkipQualIdent() {
9703 ASSERT(IsIdentifier()); 9708 ASSERT(IsIdentifier());
9704 ConsumeToken(); 9709 ConsumeToken();
9705 if (CurrentToken() == Token::kPERIOD) { 9710 if (CurrentToken() == Token::kPERIOD) {
9706 ConsumeToken(); // Consume the kPERIOD token. 9711 ConsumeToken(); // Consume the kPERIOD token.
9707 ExpectIdentifier("identifier expected after '.'"); 9712 ExpectIdentifier("identifier expected after '.'");
9708 } 9713 }
9709 } 9714 }
9710 9715
9711 } // namespace dart 9716 } // namespace dart
OLDNEW
« 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