Skip to content

Commit

Permalink
Prevent nullpo in LuaMenu Reload call (#481)
Browse files Browse the repository at this point in the history
* 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 de701e7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rts/System/SpringApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);

Expand Down

0 comments on commit de701e7

Please sign in to comment.