Skip to content
Permalink
Browse files

Prevent nullpo in LuaMenu Reload call (#481)

* Prevent nullpo in LuaMenu Reload call

`game` can be a null pointer when LuaMenu calls `SpringApp::Reload`.

In practice this didn't cause many problems, as this gets optimised as
a fixed function call, with a null `this` parameter. This led it to be
left unnoticed.

However, when using tools that are stricter about bad behaviour
(-fsanitize=...), this would detect a null pointer dereference and
abort the program.
  • Loading branch information...
esainane authored and rtri committed Nov 3, 2019
1 parent 06cccc5 commit de701e7b79ea454b49ef4cfc04e7eacf0277ef28
Showing with 3 additions and 2 deletions.
  1. +3 −2 rts/System/SpringApp.cpp
@@ -651,8 +651,9 @@ void SpringApp::Reload(const std::string script)
clientNet->ResetDemoRecorder();

// Lua shutdown functions need to access 'game' but spring::SafeDelete sets it to NULL.
// ~CGame also calls this, which does not matter because handlers are gone by then
game->KillLua(false);
// ~CGame also calls this, which does not matter because Lua handlers are gone by then
if (game != nullptr)
game->KillLua(false);

LOG("[SpringApp::%s][3]", __func__);

0 comments on commit de701e7

Please sign in to comment.
You can’t perform that action at this time.