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

Side by Side Diff: src/bootstrapper.cc

Issue 371068: Fix small memory leak in new serialization code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month 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 | « src/bootstrapper.h ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 FixedArray* cache_; 90 FixedArray* cache_;
91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache); 91 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
92 }; 92 };
93 93
94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE); 94 static SourceCodeCache natives_cache(Script::TYPE_NATIVE);
95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); 95 static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION);
96 // This is for delete, not delete[]. 96 // This is for delete, not delete[].
97 static List<char*>* delete_these_non_arrays_on_tear_down = NULL; 97 static List<char*>* delete_these_non_arrays_on_tear_down = NULL;
98 98
99 99
100 NativesExternalStringResource::NativesExternalStringResource(const char* source)
101 : data_(source), length_(strlen(source)) {
102 if (delete_these_non_arrays_on_tear_down == NULL) {
103 delete_these_non_arrays_on_tear_down = new List<char*>(2);
104 }
105 // The resources are small objects and we only make a fixed number of
106 // them, but let's clean them up on exit for neatness.
107 delete_these_non_arrays_on_tear_down->
108 Add(reinterpret_cast<char*>(this));
109 }
110
111
100 Handle<String> Bootstrapper::NativesSourceLookup(int index) { 112 Handle<String> Bootstrapper::NativesSourceLookup(int index) {
101 ASSERT(0 <= index && index < Natives::GetBuiltinsCount()); 113 ASSERT(0 <= index && index < Natives::GetBuiltinsCount());
102 if (Heap::natives_source_cache()->get(index)->IsUndefined()) { 114 if (Heap::natives_source_cache()->get(index)->IsUndefined()) {
103 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) { 115 if (!Snapshot::IsEnabled() || FLAG_new_snapshot) {
104 if (delete_these_non_arrays_on_tear_down == NULL) {
105 delete_these_non_arrays_on_tear_down = new List<char*>(2);
106 }
107 // We can use external strings for the natives. 116 // We can use external strings for the natives.
108 NativesExternalStringResource* resource = 117 NativesExternalStringResource* resource =
109 new NativesExternalStringResource( 118 new NativesExternalStringResource(
110 Natives::GetScriptSource(index).start()); 119 Natives::GetScriptSource(index).start());
111 // The resources are small objects and we only make a fixed number of
112 // them, but lets clean them up on exit for neatness.
113 delete_these_non_arrays_on_tear_down->
114 Add(reinterpret_cast<char*>(resource));
115 Handle<String> source_code = 120 Handle<String> source_code =
116 Factory::NewExternalStringFromAscii(resource); 121 Factory::NewExternalStringFromAscii(resource);
117 Heap::natives_source_cache()->set(index, *source_code); 122 Heap::natives_source_cache()->set(index, *source_code);
118 } else { 123 } else {
119 // Old snapshot code can't cope with external strings at all. 124 // Old snapshot code can't cope with external strings at all.
120 Handle<String> source_code = 125 Handle<String> source_code =
121 Factory::NewStringFromAscii(Natives::GetScriptSource(index)); 126 Factory::NewStringFromAscii(Natives::GetScriptSource(index));
122 Heap::natives_source_cache()->set(index, *source_code); 127 Heap::natives_source_cache()->set(index, *source_code);
123 } 128 }
124 } 129 }
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 } 1638 }
1634 1639
1635 1640
1636 // Restore statics that are thread local. 1641 // Restore statics that are thread local.
1637 char* Genesis::RestoreState(char* from) { 1642 char* Genesis::RestoreState(char* from) {
1638 current_ = *reinterpret_cast<Genesis**>(from); 1643 current_ = *reinterpret_cast<Genesis**>(from);
1639 return from + sizeof(current_); 1644 return from + sizeof(current_);
1640 } 1645 }
1641 1646
1642 } } // namespace v8::internal 1647 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698