diff options
author | Charles Pigott <charlespigott@googlemail.com> | 2019-11-02 12:50:42 +0000 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-11-15 21:06:09 +0100 |
commit | 60cbddbb5faf75e3c2df1e037eed759997dfa541 (patch) | |
tree | 4f02ba7443f509122664eaaff733c27886bfbed0 /src | |
parent | cf354f666804c67dfb7ddfeceda4a6306acdb09e (diff) | |
download | openttd-60cbddbb5faf75e3c2df1e037eed759997dfa541.tar.xz |
Fix #7606: Game crash when trying to clean up a crashed script
Also fix another possible memory leak
Diffstat (limited to 'src')
-rw-r--r-- | src/script/script_instance.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 2c83e8838..a38a315ff 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -89,6 +89,10 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na /* Create the main-class */ this->instance = new SQObject(); if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) { + /* If CreateClassInstance has returned false instance has not been + * registered with squirrel, so avoid trying to Release it by clearing it now */ + delete this->instance; + this->instance = nullptr; this->Died(); return; } @@ -154,6 +158,7 @@ void ScriptInstance::Died() this->last_allocated_memory = this->GetAllocatedMemory(); // Update cache if (this->instance != nullptr) this->engine->ReleaseObject(this->instance); + delete this->instance; delete this->engine; this->instance = nullptr; this->engine = nullptr; |