Skip to content

Commit

Permalink
Fix #7606: Game crash when trying to clean up a crashed script
Browse files Browse the repository at this point in the history
Also fix another possible memory leak
  • Loading branch information
LordAro authored and nielsmh committed Nov 15, 2019
1 parent cf354f6 commit 60cbddb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/script/script_instance.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 60cbddb

Please sign in to comment.