Skip to content

Commit c67693a

Browse files
committed
Fix memory leaks in Destiny testcase. Now sanitizers can be enabled in the workflow.
1 parent 0630eb1 commit c67693a

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

.github/workflows/stable-compilation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
VER="(GA, `date +%Y-%m-%d`)"
6666
cmake -G Ninja -B build . \
6767
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
68-
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wdeprecated" \
68+
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wdeprecated -fsanitize=address,undefined" \
6969
-DPLAYER_BUILD_LIBLCF=ON -DPLAYER_VERSION_APPEND="$VER"
7070
cmake --build build
7171

tests/game_destiny.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
TEST_SUITE_BEGIN("Game_Destiny");
77

88

9-
static const lcf::rpg::EventCommand* MakeCommand(
9+
static lcf::rpg::EventCommand MakeCommand(
1010
const lcf::rpg::EventCommand::Code code,
1111
const std::string& string
1212
)
1313
{
14-
lcf::rpg::EventCommand* cmd = new lcf::rpg::EventCommand;
14+
lcf::rpg::EventCommand cmd;
1515
lcf::DBString dbStr(string);
1616

17-
cmd->code = static_cast<uint32_t>(code);
18-
cmd->string = dbStr;
17+
cmd.code = static_cast<uint32_t>(code);
18+
cmd.string = dbStr;
1919

2020
return cmd;
2121
}
2222

23-
static lcf::rpg::SaveEventExecFrame* MakeFrame(
23+
static lcf::rpg::SaveEventExecFrame MakeFrame(
2424
std::vector<std::string>::const_iterator begin,
2525
std::vector<std::string>::const_iterator end
2626
)
2727
{
28-
lcf::rpg::SaveEventExecFrame* frame = new lcf::rpg::SaveEventExecFrame;
28+
lcf::rpg::SaveEventExecFrame frame;
2929
lcf::rpg::EventCommand::Code code;
3030

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

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

@@ -49,18 +49,14 @@ TEST_CASE("AssertDestinyScript")
4949
"$",
5050
"v[1] = 10;",
5151
};
52-
lcf::rpg::SaveEventExecFrame* frame;
5352
const char* destinyScript;
5453

55-
frame = MakeFrame(lines.begin(), lines.end());
56-
destinyScript = destiny.Interpreter().MakeString(*frame);
54+
auto frame = MakeFrame(lines.begin(), lines.end());
55+
destinyScript = destiny.Interpreter().MakeString(frame);
5756

5857
CHECK_EQ(*destinyScript, '$');
5958

6059
destiny.Interpreter().FreeString();
61-
delete frame;
62-
frame = nullptr;
6360
}
6461

65-
6662
TEST_SUITE_END();

0 commit comments

Comments
 (0)