Commit 4c80924d authored by vogelheim's avatar vogelheim Committed by Commit bot

Fix memory leak in natives-external.

(Discovered when landing crrev.com/959693002)

R=jochen@chromium.org
BUG=

Review URL: https://codereview.chromium.org/960883003

Cr-Commit-Position: refs/heads/master@{#26889}
parent 9f37a8af
...@@ -5214,6 +5214,9 @@ void v8::V8::SetArrayBufferAllocator( ...@@ -5214,6 +5214,9 @@ void v8::V8::SetArrayBufferAllocator(
bool v8::V8::Dispose() { bool v8::V8::Dispose() {
i::V8::TearDown(); i::V8::TearDown();
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
i::DisposeNatives();
#endif
return true; return true;
} }
......
...@@ -132,6 +132,10 @@ class NativesHolder { ...@@ -132,6 +132,10 @@ class NativesHolder {
DCHECK(store); DCHECK(store);
holder_ = store; holder_ = store;
} }
static void Dispose() {
DCHECK(holder_);
delete holder_;
}
private: private:
static NativesStore* holder_; static NativesStore* holder_;
...@@ -157,6 +161,15 @@ void SetNativesFromFile(StartupData* natives_blob) { ...@@ -157,6 +161,15 @@ void SetNativesFromFile(StartupData* natives_blob) {
} }
/**
* Release memory allocated by SetNativesFromFile.
*/
void DisposeNatives() {
NativesHolder<CORE>::Dispose();
NativesHolder<EXPERIMENTAL>::Dispose();
}
// Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore.
// //
// (The callers expect a purely static interface, since this is how the // (The callers expect a purely static interface, since this is how the
......
...@@ -40,6 +40,7 @@ typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives; ...@@ -40,6 +40,7 @@ typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
#ifdef V8_USE_EXTERNAL_STARTUP_DATA #ifdef V8_USE_EXTERNAL_STARTUP_DATA
// Used for reading the natives at runtime. Implementation in natives-empty.cc // Used for reading the natives at runtime. Implementation in natives-empty.cc
void SetNativesFromFile(StartupData* natives_blob); void SetNativesFromFile(StartupData* natives_blob);
void DisposeNatives();
#endif #endif
} } // namespace v8::internal } } // namespace v8::internal
......
...@@ -19,6 +19,7 @@ namespace internal { ...@@ -19,6 +19,7 @@ namespace internal {
// below. This happens when compiling the mksnapshot utility. // below. This happens when compiling the mksnapshot utility.
void SetNativesFromFile(StartupData* data) { CHECK(false); } void SetNativesFromFile(StartupData* data) { CHECK(false); }
void SetSnapshotFromFile(StartupData* data) { CHECK(false); } void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
void DisposeNatives() {}
#endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment