diff options
author | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-04-15 19:49:30 +0200 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-05-11 15:34:33 +0200 |
commit | 140a96b3a0fa652b66c701ac941cebc17ff24622 (patch) | |
tree | ec64deb3e7ef5032dc18991cf5bb0d4eede52fb5 /src/script/script_instance.cpp | |
parent | c9fe6e7b8fde3a23f6aab3b55fd8cca639d49696 (diff) | |
download | openttd-140a96b3a0fa652b66c701ac941cebc17ff24622.tar.xz |
Change: Limit memory allocations for each Squirrel instance
This can avoid out-of-memory situations due to single scripts using up the entire address space.
Instead, scripts that go above the maximum are killed.
The maximum is default 1 GB per script, but can be configured by a setting.
Diffstat (limited to 'src/script/script_instance.cpp')
-rw-r--r-- | src/script/script_instance.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 336d3366a..9670e37c1 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -153,6 +153,8 @@ void ScriptInstance::Died() DEBUG(script, 0, "The script died unexpectedly."); this->is_dead = true; + this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache + if (this->instance != nullptr) this->engine->ReleaseObject(this->instance); delete this->engine; this->instance = nullptr; @@ -698,3 +700,9 @@ void ScriptInstance::InsertEvent(class ScriptEvent *event) ScriptEventController::InsertEvent(event); } + +size_t ScriptInstance::GetAllocatedMemory() const +{ + if (this->engine == nullptr) return this->last_allocated_memory; + return this->engine->GetAllocatedMemory(); +} |