mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Resolve memory leaks in the unit tests and benchmarks (found by coverity)
These shouldn't really matter, but it's nice to be leak-free.
This commit is contained in:
@@ -164,6 +164,7 @@ bench_onion_TAP(void)
|
||||
int s;
|
||||
dh = crypto_dh_dup(dh_out);
|
||||
s = onion_skin_TAP_client_handshake(dh, or, key_out, sizeof(key_out));
|
||||
crypto_dh_free(dh);
|
||||
tor_assert(s == 0);
|
||||
}
|
||||
end = perftime();
|
||||
@@ -203,6 +204,7 @@ bench_onion_ntor(void)
|
||||
end = perftime();
|
||||
printf("Client-side, part 1: %f usec.\n", NANOCOUNT(start, end, iters)/1e3);
|
||||
|
||||
state = NULL;
|
||||
onion_skin_ntor_create(nodeid, &keypair1.pubkey, &state, os);
|
||||
start = perftime();
|
||||
for (i = 0; i < iters; ++i) {
|
||||
|
||||
@@ -1789,6 +1789,7 @@ test_geoip(void)
|
||||
|
||||
done:
|
||||
tor_free(s);
|
||||
tor_free(v);
|
||||
}
|
||||
|
||||
/** Run unit tests for stats code. */
|
||||
|
||||
@@ -1082,6 +1082,7 @@ test_crypto_curve25519_persist(void *arg)
|
||||
tt_int_op(0,==,curve25519_keypair_write_to_file(&keypair, fname, "testing"));
|
||||
tt_int_op(0,==,curve25519_keypair_read_from_file(&keypair2, &tag, fname));
|
||||
tt_str_op(tag,==,"testing");
|
||||
tor_free(tag);
|
||||
|
||||
test_memeq(keypair.pubkey.public_key,
|
||||
keypair2.pubkey.public_key,
|
||||
@@ -1109,6 +1110,7 @@ test_crypto_curve25519_persist(void *arg)
|
||||
fname = tor_strdup(get_fname("bogus_keypair"));
|
||||
|
||||
tt_int_op(-1, ==, curve25519_keypair_read_from_file(&keypair2, &tag, fname));
|
||||
tor_free(tag);
|
||||
|
||||
content[69] ^= 0xff;
|
||||
tt_int_op(0, ==, write_bytes_to_file(fname, content, st.st_size, 1));
|
||||
@@ -1117,6 +1119,7 @@ test_crypto_curve25519_persist(void *arg)
|
||||
done:
|
||||
tor_free(fname);
|
||||
tor_free(content);
|
||||
tor_free(tag);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+14
-10
@@ -43,13 +43,11 @@ client1(int argc, char **argv)
|
||||
/* client1 nodeID B -> msg state */
|
||||
curve25519_public_key_t B;
|
||||
uint8_t node_id[DIGEST_LEN];
|
||||
ntor_handshake_state_t *state;
|
||||
ntor_handshake_state_t *state = NULL;
|
||||
uint8_t msg[NTOR_ONIONSKIN_LEN];
|
||||
|
||||
char buf[1024];
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
N_ARGS(4);
|
||||
BASE16(2, node_id, DIGEST_LEN);
|
||||
BASE16(3, B.public_key, CURVE25519_PUBKEY_LEN);
|
||||
@@ -63,6 +61,7 @@ client1(int argc, char **argv)
|
||||
printf("%s\n", buf);
|
||||
base16_encode(buf, sizeof(buf), (void*)state, sizeof(*state));
|
||||
printf("%s\n", buf);
|
||||
|
||||
ntor_handshake_state_free(state);
|
||||
return 0;
|
||||
}
|
||||
@@ -77,8 +76,9 @@ server1(int argc, char **argv)
|
||||
int keybytes;
|
||||
|
||||
uint8_t msg_out[NTOR_REPLY_LEN];
|
||||
uint8_t *keys;
|
||||
char *hexkeys;
|
||||
uint8_t *keys = NULL;
|
||||
char *hexkeys = NULL;
|
||||
int result = 0;
|
||||
|
||||
char buf[256];
|
||||
|
||||
@@ -98,7 +98,8 @@ server1(int argc, char **argv)
|
||||
msg_in, keymap, NULL, node_id, msg_out, keys,
|
||||
(size_t)keybytes)<0) {
|
||||
fprintf(stderr, "handshake failed");
|
||||
return 2;
|
||||
result = 2;
|
||||
goto done;
|
||||
}
|
||||
|
||||
base16_encode(buf, sizeof(buf), (const char*)msg_out, sizeof(msg_out));
|
||||
@@ -106,9 +107,10 @@ server1(int argc, char **argv)
|
||||
base16_encode(hexkeys, keybytes*2+1, (const char*)keys, keybytes);
|
||||
printf("%s\n", hexkeys);
|
||||
|
||||
done:
|
||||
tor_free(keys);
|
||||
tor_free(hexkeys);
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -119,6 +121,7 @@ client2(int argc, char **argv)
|
||||
int keybytes;
|
||||
uint8_t *keys;
|
||||
char *hexkeys;
|
||||
int result = 0;
|
||||
|
||||
N_ARGS(5);
|
||||
BASE16(2, (&state), sizeof(state));
|
||||
@@ -129,16 +132,17 @@ client2(int argc, char **argv)
|
||||
hexkeys = tor_malloc(keybytes*2+1);
|
||||
if (onion_skin_ntor_client_handshake(&state, msg, keys, keybytes)<0) {
|
||||
fprintf(stderr, "handshake failed");
|
||||
return 2;
|
||||
result = 2;
|
||||
goto done;
|
||||
}
|
||||
|
||||
base16_encode(hexkeys, keybytes*2+1, (const char*)keys, keybytes);
|
||||
printf("%s\n", hexkeys);
|
||||
|
||||
done:
|
||||
tor_free(keys);
|
||||
tor_free(hexkeys);
|
||||
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -2724,7 +2724,7 @@ test_util_join_win_cmdline(void *ptr)
|
||||
}
|
||||
|
||||
done:
|
||||
;
|
||||
tor_free(joined_argv);
|
||||
}
|
||||
|
||||
#define MAX_SPLIT_LINE_COUNT 4
|
||||
|
||||
Reference in New Issue
Block a user