Skip to content

Commit 554e7cd

Browse files
committed
refactor: Add mem module to allow tests to override allocators.
This will allow us to do more interesting things with memory allocation within toxcore, and allow fuzzers to explore various allocation failure paths.
1 parent 8ed47f3 commit 554e7cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+764
-398
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ set(toxcore_SOURCES
268268
toxcore/logger.h
269269
toxcore/Messenger.c
270270
toxcore/Messenger.h
271+
toxcore/mem.c
272+
toxcore/mem.h
271273
toxcore/mono_time.c
272274
toxcore/mono_time.h
273275
toxcore/net_crypto.c
@@ -434,6 +436,7 @@ unit_test(toxcore bin_pack)
434436
unit_test(toxcore crypto_core)
435437
unit_test(toxcore group_announce)
436438
unit_test(toxcore group_moderation)
439+
unit_test(toxcore mem)
437440
unit_test(toxcore mono_time)
438441
unit_test(toxcore ping_array)
439442
unit_test(toxcore tox)

auto_tests/TCP_test.c

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ static void test_basic(void)
4848
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
4949
const Random *rng = system_random();
5050
ck_assert(rng != nullptr);
51+
const Network *ns = system_network();
52+
ck_assert(ns != nullptr);
53+
const Memory *mem = system_memory();
54+
ck_assert(mem != nullptr);
55+
5156
Logger *logger = logger_new();
5257
logger_callback_log(logger, print_debug_logger, nullptr, nullptr);
5358

5459
// Attempt to create a new TCP_Server instance.
5560
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
5661
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
5762
crypto_new_keypair(rng, self_public_key, self_secret_key);
58-
const Network *ns = system_network();
59-
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
63+
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
6064
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
6165
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS,
6266
"Failed to bind a TCP relay server to all %d attempted ports.", NUM_PORTS);
@@ -70,7 +74,7 @@ static void test_basic(void)
7074
for (uint8_t i = 0; i < NUM_PORTS; i++) {
7175
sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
7276
localhost.port = net_htons(ports[i]);
73-
bool ret = net_connect(logger, sock, &localhost);
77+
bool ret = net_connect(mem, logger, sock, &localhost);
7478
ck_assert_msg(ret, "Failed to connect to created TCP relay server on port %d (%d).", ports[i], errno);
7579

7680
// Leave open one connection for the next test.
@@ -190,24 +194,26 @@ static void test_basic(void)
190194
struct sec_TCP_con {
191195
Socket sock;
192196
const Network *ns;
197+
const Memory *mem;
193198
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
194199
uint8_t recv_nonce[CRYPTO_NONCE_SIZE];
195200
uint8_t sent_nonce[CRYPTO_NONCE_SIZE];
196201
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
197202
};
198203

199-
static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
204+
static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
200205
{
201206
struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con));
202207
ck_assert(sec_c != nullptr);
203208
sec_c->ns = ns;
209+
sec_c->mem = mem;
204210
Socket sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
205211

206212
IP_Port localhost;
207213
localhost.ip = get_loopback();
208214
localhost.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
209215

210-
bool ok = net_connect(logger, sock, &localhost);
216+
bool ok = net_connect(mem, logger, sock, &localhost);
211217
ck_assert_msg(ok, "Failed to connect to the test TCP relay server.");
212218

213219
uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE];
@@ -302,17 +308,20 @@ static void test_some(void)
302308
ck_assert(rng != nullptr);
303309
Logger *logger = logger_new();
304310
const Network *ns = system_network();
311+
ck_assert(ns != nullptr);
312+
const Memory *mem = system_memory();
313+
ck_assert(mem != nullptr);
305314

306315
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
307316
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
308317
crypto_new_keypair(rng, self_public_key, self_secret_key);
309-
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
318+
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
310319
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
311320
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports.");
312321

313-
struct sec_TCP_con *con1 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
314-
struct sec_TCP_con *con2 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
315-
struct sec_TCP_con *con3 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
322+
struct sec_TCP_con *con1 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
323+
struct sec_TCP_con *con2 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
324+
struct sec_TCP_con *con3 = new_TCP_con(logger, mem, rng, ns, tcp_s, mono_time);
316325

317326
uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE];
318327
requ_p[0] = TCP_PACKET_ROUTING_REQUEST;
@@ -492,12 +501,15 @@ static void test_client(void)
492501
const Random *rng = system_random();
493502
ck_assert(rng != nullptr);
494503
Logger *logger = logger_new();
504+
const Network *ns = system_network();
505+
ck_assert(ns != nullptr);
506+
const Memory *mem = system_memory();
507+
ck_assert(mem != nullptr);
495508

496509
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
497510
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
498511
crypto_new_keypair(rng, self_public_key, self_secret_key);
499-
const Network *ns = system_network();
500-
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
512+
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
501513
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
502514
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind the relay server to all ports.");
503515

@@ -509,8 +521,7 @@ static void test_client(void)
509521
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
510522
ip_port_tcp_s.ip = get_loopback();
511523

512-
TCP_Client_Connection *conn = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key,
513-
f_secret_key, nullptr);
524+
TCP_Client_Connection *conn = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
514525
do_TCP_connection(logger, mono_time, conn, nullptr);
515526
c_sleep(50);
516527

@@ -544,7 +555,7 @@ static void test_client(void)
544555
uint8_t f2_secret_key[CRYPTO_SECRET_KEY_SIZE];
545556
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
546557
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
547-
TCP_Client_Connection *conn2 = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
558+
TCP_Client_Connection *conn2 = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
548559
f2_secret_key, nullptr);
549560

550561
// The client should call this function (defined earlier) during the routing process.
@@ -622,8 +633,11 @@ static void test_client_invalid(void)
622633
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
623634
const Random *rng = system_random();
624635
ck_assert(rng != nullptr);
625-
Logger *logger = logger_new();
626636
const Network *ns = system_network();
637+
ck_assert(ns != nullptr);
638+
const Memory *mem = system_memory();
639+
ck_assert(mem != nullptr);
640+
Logger *logger = logger_new();
627641

628642
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
629643
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
@@ -636,7 +650,7 @@ static void test_client_invalid(void)
636650

637651
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
638652
ip_port_tcp_s.ip = get_loopback();
639-
TCP_Client_Connection *conn = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s,
653+
TCP_Client_Connection *conn = new_TCP_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
640654
self_public_key, f_public_key, f_secret_key, nullptr);
641655

642656
// Run the client's main loop but not the server.
@@ -699,22 +713,25 @@ static void test_tcp_connection(void)
699713
const Random *rng = system_random();
700714
ck_assert(rng != nullptr);
701715
const Network *ns = system_network();
716+
ck_assert(ns != nullptr);
717+
const Memory *mem = system_memory();
718+
ck_assert(mem != nullptr);
702719

703720
tcp_data_callback_called = 0;
704721
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
705722
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
706723
crypto_new_keypair(rng, self_public_key, self_secret_key);
707-
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
724+
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
708725
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
709726

710727
TCP_Proxy_Info proxy_info;
711728
proxy_info.proxy_type = TCP_PROXY_NONE;
712729
crypto_new_keypair(rng, self_public_key, self_secret_key);
713-
TCP_Connections *tc_1 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
730+
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
714731
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
715732

716733
crypto_new_keypair(rng, self_public_key, self_secret_key);
717-
TCP_Connections *tc_2 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
734+
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
718735
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
719736

720737
IP_Port ip_port_tcp_s;
@@ -808,24 +825,27 @@ static void test_tcp_connection2(void)
808825
const Random *rng = system_random();
809826
ck_assert(rng != nullptr);
810827
const Network *ns = system_network();
828+
ck_assert(ns != nullptr);
829+
const Memory *mem = system_memory();
830+
ck_assert(mem != nullptr);
811831

812832
tcp_oobdata_callback_called = 0;
813833
tcp_data_callback_called = 0;
814834

815835
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
816836
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
817837
crypto_new_keypair(rng, self_public_key, self_secret_key);
818-
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
838+
TCP_Server *tcp_s = new_TCP_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
819839
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
820840

821841
TCP_Proxy_Info proxy_info;
822842
proxy_info.proxy_type = TCP_PROXY_NONE;
823843
crypto_new_keypair(rng, self_public_key, self_secret_key);
824-
TCP_Connections *tc_1 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
844+
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
825845
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
826846

827847
crypto_new_keypair(rng, self_public_key, self_secret_key);
828-
TCP_Connections *tc_2 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
848+
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
829849
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
830850

831851
IP_Port ip_port_tcp_s;

auto_tests/announce_test.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ static void test_store_data(void)
5454
ck_assert(rng != nullptr);
5555
const Network *ns = system_network();
5656
ck_assert(ns != nullptr);
57+
const Memory *mem = system_memory();
58+
ck_assert(mem != nullptr);
59+
5760
Logger *log = logger_new();
5861
ck_assert(log != nullptr);
5962
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
6063
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
61-
Networking_Core *net = new_networking_no_udp(log, ns);
62-
DHT *dht = new_dht(log, rng, ns, mono_time, net, true, true);
64+
Networking_Core *net = new_networking_no_udp(log, mem, ns);
65+
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
6366
Forwarding *forwarding = new_forwarding(log, rng, mono_time, dht);
64-
Announcements *announce = new_announcements(log, rng, mono_time, forwarding);
67+
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
6568
ck_assert(announce != nullptr);
6669

6770
/* Just to prevent CI from complaining that set_synch_offset is unused: */

auto_tests/forwarding_test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,25 @@ static Forwarding_Subtox *new_forwarding_subtox(bool no_udp, uint32_t *index, ui
116116
ck_assert(rng != nullptr);
117117
const Network *ns = system_network();
118118
ck_assert(ns != nullptr);
119+
const Memory *mem = system_memory();
120+
ck_assert(mem != nullptr);
119121

120122
if (no_udp) {
121-
subtox->net = new_networking_no_udp(subtox->log, ns);
123+
subtox->net = new_networking_no_udp(subtox->log, mem, ns);
122124
} else {
123125
const IP ip = get_loopback();
124-
subtox->net = new_networking_ex(subtox->log, ns, &ip, port, port, nullptr);
126+
subtox->net = new_networking_ex(subtox->log, mem, ns, &ip, port, port, nullptr);
125127
}
126128

127-
subtox->dht = new_dht(subtox->log, rng, ns, subtox->mono_time, subtox->net, true, true);
129+
subtox->dht = new_dht(subtox->log, mem, rng, ns, subtox->mono_time, subtox->net, true, true);
128130

129131
const TCP_Proxy_Info inf = {{{{0}}}};
130-
subtox->c = new_net_crypto(subtox->log, rng, ns, subtox->mono_time, subtox->dht, &inf);
132+
subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf);
131133

132134
subtox->forwarding = new_forwarding(subtox->log, rng, subtox->mono_time, subtox->dht);
133135
ck_assert(subtox->forwarding != nullptr);
134136

135-
subtox->announce = new_announcements(subtox->log, rng, subtox->mono_time, subtox->forwarding);
137+
subtox->announce = new_announcements(subtox->log, mem, rng, subtox->mono_time, subtox->forwarding);
136138
ck_assert(subtox->announce != nullptr);
137139

138140
return subtox;

auto_tests/onion_test.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,32 @@ static void send_onion_packet(const Networking_Core *net, const Random *rng, con
215215
/** Initialize networking.
216216
* Added for reverse compatibility with old new_networking calls.
217217
*/
218-
static Networking_Core *new_networking(const Logger *log, const Network *ns, const IP *ip, uint16_t port)
218+
static Networking_Core *new_networking(const Logger *log, const Memory *mem, const Network *ns, const IP *ip, uint16_t port)
219219
{
220-
return new_networking_ex(log, ns, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
220+
return new_networking_ex(log, mem, ns, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
221221
}
222222

223223
static void test_basic(void)
224224
{
225225
uint32_t index[] = { 1, 2, 3 };
226226
const Network *ns = system_network();
227+
ck_assert(ns != nullptr);
228+
const Memory *mem = system_memory();
229+
ck_assert(mem != nullptr);
230+
const Random *rng = system_random();
231+
ck_assert(rng != nullptr);
227232

228233
Logger *log1 = logger_new();
229234
logger_callback_log(log1, print_debug_logger, nullptr, &index[0]);
230235
Logger *log2 = logger_new();
231236
logger_callback_log(log2, print_debug_logger, nullptr, &index[1]);
232237

233-
const Random *rng = system_random();
234-
ck_assert(rng != nullptr);
235238
Mono_Time *mono_time1 = mono_time_new(nullptr, nullptr);
236239
Mono_Time *mono_time2 = mono_time_new(nullptr, nullptr);
237240

238241
IP ip = get_loopback();
239-
Onion *onion1 = new_onion(log1, mono_time1, rng, new_dht(log1, rng, ns, mono_time1, new_networking(log1, ns, &ip, 36567), true, false));
240-
Onion *onion2 = new_onion(log2, mono_time2, rng, new_dht(log2, rng, ns, mono_time2, new_networking(log2, ns, &ip, 36568), true, false));
242+
Onion *onion1 = new_onion(log1, mem, mono_time1, rng, new_dht(log1, mem, rng, ns, mono_time1, new_networking(log1, mem, ns, &ip, 36567), true, false));
243+
Onion *onion2 = new_onion(log2, mem, mono_time2, rng, new_dht(log2, mem, rng, ns, mono_time2, new_networking(log2, mem, ns, &ip, 36568), true, false));
241244
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
242245
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
243246

@@ -280,8 +283,8 @@ static void test_basic(void)
280283
do_onion(mono_time2, onion2);
281284
} while (handled_test_2 == 0);
282285

283-
Onion_Announce *onion1_a = new_onion_announce(log1, rng, mono_time1, onion1->dht);
284-
Onion_Announce *onion2_a = new_onion_announce(log2, rng, mono_time2, onion2->dht);
286+
Onion_Announce *onion1_a = new_onion_announce(log1, mem, rng, mono_time1, onion1->dht);
287+
Onion_Announce *onion2_a = new_onion_announce(log2, mem, rng, mono_time2, onion2->dht);
285288
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
286289
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE_OLD, &handle_test_3_old, onion1);
287290
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
@@ -333,7 +336,7 @@ static void test_basic(void)
333336

334337
Mono_Time *mono_time3 = mono_time_new(nullptr, nullptr);
335338

336-
Onion *onion3 = new_onion(log3, mono_time3, rng, new_dht(log3, rng, ns, mono_time3, new_networking(log3, ns, &ip, 36569), true, false));
339+
Onion *onion3 = new_onion(log3, mem, mono_time3, rng, new_dht(log3, mem, rng, ns, mono_time3, new_networking(log3, mem, ns, &ip, 36569), true, false));
337340
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
338341

339342
random_nonce(rng, nonce);
@@ -400,7 +403,7 @@ typedef struct {
400403
Onion_Client *onion_c;
401404
} Onions;
402405

403-
static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
406+
static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, uint32_t *index)
404407
{
405408
IP ip = get_loopback();
406409
ip.ip.v6.uint8[15] = 1;
@@ -428,7 +431,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
428431
return nullptr;
429432
}
430433

431-
Networking_Core *net = new_networking(on->log, ns, &ip, port);
434+
Networking_Core *net = new_networking(on->log, mem, ns, &ip, port);
432435

433436
if (!net) {
434437
mono_time_free(on->mono_time);
@@ -437,7 +440,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
437440
return nullptr;
438441
}
439442

440-
DHT *dht = new_dht(on->log, rng, ns, on->mono_time, net, true, false);
443+
DHT *dht = new_dht(on->log, mem, rng, ns, on->mono_time, net, true, false);
441444

442445
if (!dht) {
443446
kill_networking(net);
@@ -447,7 +450,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
447450
return nullptr;
448451
}
449452

450-
on->onion = new_onion(on->log, on->mono_time, rng, dht);
453+
on->onion = new_onion(on->log, mem, on->mono_time, rng, dht);
451454

452455
if (!on->onion) {
453456
kill_dht(dht);
@@ -458,7 +461,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
458461
return nullptr;
459462
}
460463

461-
on->onion_a = new_onion_announce(on->log, rng, on->mono_time, dht);
464+
on->onion_a = new_onion_announce(on->log, mem, rng, on->mono_time, dht);
462465

463466
if (!on->onion_a) {
464467
kill_onion(on->onion);
@@ -471,7 +474,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
471474
}
472475

473476
TCP_Proxy_Info inf = {{{{0}}}};
474-
on->onion_c = new_onion_client(on->log, rng, on->mono_time, new_net_crypto(on->log, rng, ns, on->mono_time, dht, &inf));
477+
on->onion_c = new_onion_client(on->log, mem, rng, on->mono_time, new_net_crypto(on->log, mem, rng, ns, on->mono_time, dht, &inf));
475478

476479
if (!on->onion_c) {
477480
kill_onion_announce(on->onion_a);
@@ -576,10 +579,12 @@ static void test_announce(void)
576579
Onions *onions[NUM_ONIONS];
577580
const Random *rng = system_random();
578581
ck_assert(rng != nullptr);
582+
const Memory *mem = system_memory();
583+
ck_assert(mem != nullptr);
579584

580585
for (i = 0; i < NUM_ONIONS; ++i) {
581586
index[i] = i + 1;
582-
onions[i] = new_onions(rng, i + 36655, &index[i]);
587+
onions[i] = new_onions(mem, rng, i + 36655, &index[i]);
583588
ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i);
584589
}
585590

0 commit comments

Comments
 (0)