Index: src/bootstrapper.cc |
=================================================================== |
--- src/bootstrapper.cc (revision 3439) |
+++ src/bootstrapper.cc (working copy) |
@@ -95,6 +95,8 @@ |
static SourceCodeCache extensions_cache(Script::TYPE_EXTENSION); |
// This is for delete, not delete[]. |
static List<char*>* delete_these_non_arrays_on_tear_down = NULL; |
+// This is for delete[] |
+static List<char*>* delete_these_arrays_on_tear_down = NULL; |
NativesExternalStringResource::NativesExternalStringResource(const char* source) |
@@ -150,17 +152,41 @@ |
} |
+char* Bootstrapper::AllocateAutoDeletedArray(int bytes) { |
+ char* memory = new char[bytes]; |
+ if (memory != NULL) { |
+ if (delete_these_arrays_on_tear_down == NULL) { |
+ delete_these_arrays_on_tear_down = new List<char*>(2); |
+ } |
+ delete_these_arrays_on_tear_down->Add(memory); |
+ } |
+ return memory; |
+} |
+ |
+ |
void Bootstrapper::TearDown() { |
if (delete_these_non_arrays_on_tear_down != NULL) { |
int len = delete_these_non_arrays_on_tear_down->length(); |
ASSERT(len < 20); // Don't use this mechanism for unbounded allocations. |
for (int i = 0; i < len; i++) { |
delete delete_these_non_arrays_on_tear_down->at(i); |
+ delete_these_non_arrays_on_tear_down->at(i) = NULL; |
} |
delete delete_these_non_arrays_on_tear_down; |
delete_these_non_arrays_on_tear_down = NULL; |
} |
+ if (delete_these_arrays_on_tear_down != NULL) { |
+ int len = delete_these_arrays_on_tear_down->length(); |
+ ASSERT(len < 1000); // Don't use this mechanism for unbounded allocations. |
+ for (int i = 0; i < len; i++) { |
+ delete[] delete_these_arrays_on_tear_down->at(i); |
+ delete_these_arrays_on_tear_down->at(i) = NULL; |
+ } |
+ delete delete_these_arrays_on_tear_down; |
+ delete_these_arrays_on_tear_down = NULL; |
+ } |
+ |
natives_cache.Initialize(false); // Yes, symmetrical |
extensions_cache.Initialize(false); |
} |