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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user