aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-10-30 18:39:48 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-10-31 12:03:22 +0000
commit5ae02988184bc8e837830d1320b51c8577c12c91 (patch)
tree20f4f99aea68e1654e01c1d5675d09545b8e742a /tests
parentMerge pull request #6045 (diff)
downloadmonero-5ae02988184bc8e837830d1320b51c8577c12c91.tar.xz
unit_tests: fix use after free
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/node_server.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index 2c89323c7..5f91fc6d4 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -262,16 +262,25 @@ TEST(ban, ignores_port)
TEST(node_server, bind_same_p2p_port)
{
- const auto new_node = []() -> std::unique_ptr<Server> {
+ struct test_data_t
+ {
test_core pr_core;
- cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
- std::unique_ptr<Server> server(new Server(cprotocol));
- cprotocol.set_p2p_endpoint(server.get());
+ cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol;
+ std::unique_ptr<Server> server;
+
+ test_data_t(): cprotocol(pr_core, NULL)
+ {
+ server.reset(new Server(cprotocol));
+ cprotocol.set_p2p_endpoint(server.get());
+ }
+ };
- return server;
+ const auto new_node = []() -> std::unique_ptr<test_data_t> {
+ test_data_t *d = new test_data_t;
+ return std::unique_ptr<test_data_t>(d);
};
- const auto init = [](const std::unique_ptr<Server>& server, const char* port) -> bool {
+ const auto init = [](const std::unique_ptr<test_data_t>& server, const char* port) -> bool {
boost::program_options::options_description desc_options("Command line options");
cryptonote::core::init_options(desc_options);
Server::init_options(desc_options);
@@ -284,7 +293,7 @@ TEST(node_server, bind_same_p2p_port)
boost::program_options::notify(vm);
- return server->init(vm);
+ return server->server->init(vm);
};
constexpr char port[] = "48080";