Skip to content

Commit

Permalink
Fix memory leaks in Destiny testcase. Now sanitizers can be enabled i…
Browse files Browse the repository at this point in the history
…n the workflow.
  • Loading branch information
Ghabry committed Jan 10, 2025
1 parent 0630eb1 commit c67693a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stable-compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
VER="(GA, `date +%Y-%m-%d`)"
cmake -G Ninja -B build . \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wdeprecated" \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wdeprecated -fsanitize=address,undefined" \
-DPLAYER_BUILD_LIBLCF=ON -DPLAYER_VERSION_APPEND="$VER"
cmake --build build
Expand Down
22 changes: 9 additions & 13 deletions tests/game_destiny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
TEST_SUITE_BEGIN("Game_Destiny");


static const lcf::rpg::EventCommand* MakeCommand(
static lcf::rpg::EventCommand MakeCommand(
const lcf::rpg::EventCommand::Code code,
const std::string& string
)
{
lcf::rpg::EventCommand* cmd = new lcf::rpg::EventCommand;
lcf::rpg::EventCommand cmd;
lcf::DBString dbStr(string);

cmd->code = static_cast<uint32_t>(code);
cmd->string = dbStr;
cmd.code = static_cast<uint32_t>(code);
cmd.string = dbStr;

return cmd;
}

static lcf::rpg::SaveEventExecFrame* MakeFrame(
static lcf::rpg::SaveEventExecFrame MakeFrame(
std::vector<std::string>::const_iterator begin,
std::vector<std::string>::const_iterator end
)
{
lcf::rpg::SaveEventExecFrame* frame = new lcf::rpg::SaveEventExecFrame;
lcf::rpg::SaveEventExecFrame frame;
lcf::rpg::EventCommand::Code code;

code = lcf::rpg::EventCommand::Code::Comment;
Expand All @@ -34,7 +34,7 @@ static lcf::rpg::SaveEventExecFrame* MakeFrame(
{
const std::string& str = *begin++;

frame->commands.push_back(*MakeCommand(code, str));
frame.commands.push_back(MakeCommand(code, str));
code = lcf::rpg::EventCommand::Code::Comment_2;
}

Expand All @@ -49,18 +49,14 @@ TEST_CASE("AssertDestinyScript")
"$",
"v[1] = 10;",
};
lcf::rpg::SaveEventExecFrame* frame;
const char* destinyScript;

frame = MakeFrame(lines.begin(), lines.end());
destinyScript = destiny.Interpreter().MakeString(*frame);
auto frame = MakeFrame(lines.begin(), lines.end());
destinyScript = destiny.Interpreter().MakeString(frame);

CHECK_EQ(*destinyScript, '$');

destiny.Interpreter().FreeString();
delete frame;
frame = nullptr;
}


TEST_SUITE_END();

0 comments on commit c67693a

Please sign in to comment.