summaryrefslogtreecommitdiff
path: root/src/test/test_rendcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test_rendcache.c')
-rw-r--r--src/test/test_rendcache.c221
1 files changed, 150 insertions, 71 deletions
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index f21c7c4439..11f11147cb 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -25,17 +25,16 @@ extern digestmap_t *rend_cache_v2_dir;
extern strmap_t *rend_cache_failure;
extern size_t rend_cache_total_allocation;
-static rend_data_t
-mock_rend_data(char *onion_address)
+static rend_data_t *
+mock_rend_data(const char *onion_address)
{
- rend_data_t rend_query;
-
- memset(&rend_query, 0, sizeof(rend_query));
- strncpy(rend_query.onion_address, onion_address,
- REND_SERVICE_ID_LEN_BASE32+1);
- rend_query.auth_type = REND_NO_AUTH;
- rend_query.hsdirs_fp = smartlist_new();
- smartlist_add(rend_query.hsdirs_fp, tor_memdup("aaaaaaaaaaaaaaaaaaaaaaaa",
+ rend_data_t *rend_query = tor_malloc_zero(sizeof(rend_data_t));
+
+ strlcpy(rend_query->onion_address, onion_address,
+ sizeof(rend_query->onion_address));
+ rend_query->auth_type = REND_NO_AUTH;
+ rend_query->hsdirs_fp = smartlist_new();
+ smartlist_add(rend_query->hsdirs_fp, tor_memdup("aaaaaaaaaaaaaaaaaaaaaaaa",
DIGEST_LEN));
return rend_query;
@@ -45,7 +44,7 @@ static void
test_rend_cache_lookup_entry(void *data)
{
int ret;
- rend_data_t mock_rend_query;
+ rend_data_t *mock_rend_query = NULL;
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
rend_cache_entry_t *entry = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
@@ -72,7 +71,7 @@ test_rend_cache_lookup_entry(void *data)
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
rend_cache_store_v2_desc_as_client(desc_holder->desc_str, desc_id_base32,
- &mock_rend_query, NULL);
+ mock_rend_query, NULL);
ret = rend_cache_lookup_entry(service_id, 2, NULL);
tt_int_op(ret, OP_EQ, 0);
@@ -83,16 +82,17 @@ test_rend_cache_lookup_entry(void *data)
tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
done:
- tor_free(desc_holder);
- tor_free(entry);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_cache_free_all();
+ rend_data_free(mock_rend_query);
}
static void
test_rend_cache_store_v2_desc_as_client(void *data)
{
rend_cache_store_status_t ret;
- rend_data_t mock_rend_query;
+ rend_data_t *mock_rend_query;
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
rend_cache_entry_t *entry = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
@@ -109,7 +109,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
&entry);
tt_int_op(ret, OP_EQ, RCS_OKAY);
@@ -131,41 +131,47 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// But when doing coverage, we can test it.
#ifdef TOR_COVERAGE
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- "!xqunszqnaolrrfmtzgaki7mxelgvkj", &mock_rend_query, NULL);
+ "!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
#endif
// Test invalid descriptor
ret = rend_cache_store_v2_desc_as_client("invalid descriptor",
- "3xqunszqnaolrrfmtzgaki7mxelgvkje", &mock_rend_query, NULL);
+ "3xqunszqnaolrrfmtzgaki7mxelgvkje", mock_rend_query, NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
// TODO: it doesn't seem to be possible to test invalid service ID condition.
// that means it is likely not possible to have that condition without
// earlier conditions failing first (such as signature checking of the desc)
+ rend_cache_free_all();
+
// Test mismatch between service ID and onion address
rend_cache_init();
- strncpy(mock_rend_query.onion_address, "abc", REND_SERVICE_ID_LEN_BASE32+1);
+ strncpy(mock_rend_query->onion_address, "abc", REND_SERVICE_ID_LEN_BASE32+1);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
desc_id_base32,
- &mock_rend_query, NULL);
+ mock_rend_query, NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
+ rend_cache_free_all();
+ rend_data_free(mock_rend_query);
// Test incorrect descriptor ID
rend_cache_init();
mock_rend_query = mock_rend_data(service_id);
desc_id_base32[0]++;
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
desc_id_base32[0]--;
+ rend_cache_free_all();
// Test too old descriptor
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
mock_rend_query = mock_rend_data(service_id);
@@ -174,13 +180,15 @@ test_rend_cache_store_v2_desc_as_client(void *data)
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
desc_id_base32,
- &mock_rend_query, NULL);
+ mock_rend_query, NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
+ rend_cache_free_all();
// Test too new descriptor (in the future)
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
mock_rend_query = mock_rend_data(service_id);
@@ -188,15 +196,16 @@ test_rend_cache_store_v2_desc_as_client(void *data)
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
+ rend_cache_free_all();
// Test when a descriptor is already in the cache
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
- tor_free(entry);
+ rend_data_free(mock_rend_query);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
mock_rend_query = mock_rend_data(service_id);
@@ -204,90 +213,100 @@ test_rend_cache_store_v2_desc_as_client(void *data)
DIGEST_LEN);
rend_cache_store_v2_desc_as_client(desc_holder->desc_str, desc_id_base32,
- &mock_rend_query, NULL);
+ mock_rend_query, NULL);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_OKAY);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
&entry);
tt_int_op(ret, OP_EQ, RCS_OKAY);
tt_assert(entry);
+ rend_cache_free_all();
// Test unsuccessful decrypting of introduction points
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
mock_rend_query = mock_rend_data(service_id);
- mock_rend_query.auth_type = REND_BASIC_AUTH;
+ mock_rend_query->auth_type = REND_BASIC_AUTH;
client_cookie[0] = 'A';
- memcpy(mock_rend_query.descriptor_cookie, client_cookie,
+ memcpy(mock_rend_query->descriptor_cookie, client_cookie,
REND_DESC_COOKIE_LEN);
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_cache_free_all();
// Test successful run when we have REND_BASIC_AUTH but not cookie
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
mock_rend_query = mock_rend_data(service_id);
- mock_rend_query.auth_type = REND_BASIC_AUTH;
+ mock_rend_query->auth_type = REND_BASIC_AUTH;
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_cache_free_all();
+
// Test when we have no introduction points
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 0);
mock_rend_query = mock_rend_data(service_id);
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
+ rend_cache_free_all();
// Test when we have too many intro points
rend_cache_init();
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_data_free(mock_rend_query);
generate_desc(RECENT_TIME, &desc_holder, &service_id, MAX_INTRO_POINTS+1);
mock_rend_query = mock_rend_data(service_id);
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
DIGEST_LEN);
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);
done:
rend_encoded_v2_service_descriptor_free(desc_holder);
- tor_free(entry);
tor_free(service_id);
+ rend_cache_free_all();
+ rend_data_free(mock_rend_query);
}
static void
test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
{
rend_cache_store_status_t ret;
- rend_data_t mock_rend_query;
+ rend_data_t *mock_rend_query;
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
rend_service_descriptor_t *generated = NULL;
smartlist_t *descs = smartlist_new();
@@ -297,6 +316,7 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
rend_encoded_v2_service_descriptor_t *desc_holder_older;
t = time(NULL);
+ rend_cache_init();
create_descriptor(&generated, &service_id, 3);
@@ -305,7 +325,10 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_newer = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
+ smartlist_set(descs, 0, NULL);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
descs = smartlist_new();
@@ -314,9 +337,8 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_older = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
-
+ smartlist_set(descs, 0, NULL);
(void)data;
- rend_cache_init();
// Test when a descriptor is already in the cache and it is newer than the
// one we submit
@@ -324,27 +346,33 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
base32_encode(desc_id_base32, sizeof(desc_id_base32),
desc_holder_newer->desc_id, DIGEST_LEN);
rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
- desc_id_base32, &mock_rend_query, NULL);
+ desc_id_base32, mock_rend_query, NULL);
ret = rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_cache_free_all();
+
// Test when an old descriptor is in the cache and we submit a newer one
rend_cache_init();
rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
- desc_id_base32, &mock_rend_query, NULL);
+ desc_id_base32, mock_rend_query, NULL);
ret = rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
- desc_id_base32, &mock_rend_query,
+ desc_id_base32, mock_rend_query,
NULL);
tt_int_op(ret, OP_EQ, RCS_OKAY);
done:
rend_encoded_v2_service_descriptor_free(desc_holder_newer);
rend_encoded_v2_service_descriptor_free(desc_holder_older);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
rend_service_descriptor_free(generated);
tor_free(service_id);
+ rend_cache_free_all();
+ rend_data_free(mock_rend_query);
}
#define NS_SUBMODULE lookup_v2_desc_as_dir
@@ -410,6 +438,9 @@ test_rend_cache_lookup_v2_desc_as_dir(void *data)
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
tor_free(mock_routerinfo);
+ rend_cache_free_all();
+ rend_encoded_v2_service_descriptor_free(desc_holder);
+ tor_free(service_id);
}
#undef NS_SUBMODULE
@@ -461,22 +492,34 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
+ tor_free(service_id);
+
// Test when we have an old descriptor
hid_serv_responsible_for_desc_id_response = 1;
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
+ tor_free(service_id);
+
// Test when we have a descriptor in the future
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
+ tor_free(service_id);
+
// Test when two descriptors
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
+ tor_free(service_id);
+
// Test when asking for hidden service statistics HiddenServiceStatistics
rend_cache_purge();
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
@@ -487,8 +530,10 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
done:
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
- tor_free(desc_holder);
+ rend_encoded_v2_service_descriptor_free(desc_holder);
tor_free(service_id);
+ rend_cache_free_all();
+ tor_free(mock_routerinfo);
}
static void
@@ -517,7 +562,9 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_newer = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
-
+ smartlist_set(descs, 0, NULL);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
descs = smartlist_new();
@@ -526,6 +573,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_older = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
+ smartlist_set(descs, 0, NULL);
// Test when we have a newer descriptor stored
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
@@ -543,6 +591,15 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
done:
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
+ rend_cache_free_all();
+ rend_service_descriptor_free(generated);
+ tor_free(service_id);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
+ smartlist_free(descs);
+ rend_encoded_v2_service_descriptor_free(desc_holder_newer);
+ rend_encoded_v2_service_descriptor_free(desc_holder_older);
+ tor_free(mock_routerinfo);
}
static void
@@ -555,8 +612,8 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
smartlist_t *descs = smartlist_new();
time_t t;
char *service_id = NULL;
- rend_encoded_v2_service_descriptor_t *desc_holder_one;
- rend_encoded_v2_service_descriptor_t *desc_holder_two;
+ rend_encoded_v2_service_descriptor_t *desc_holder_one = NULL;
+ rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
NS_MOCK(router_get_my_routerinfo);
NS_MOCK(hid_serv_responsible_for_desc_id);
@@ -571,7 +628,10 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_one = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
+ smartlist_set(descs, 0, NULL);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
descs = smartlist_new();
@@ -581,6 +641,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
REND_NO_AUTH, NULL, NULL);
desc_holder_two = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
+ smartlist_set(descs, 0, NULL);
// Test when we have another descriptor stored, with a different descriptor
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
@@ -592,6 +653,14 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
done:
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
+ rend_cache_free_all();
+ rend_service_descriptor_free(generated);
+ tor_free(service_id);
+ SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
+ rend_encoded_v2_service_descriptor_free(d));
+ smartlist_free(descs);
+ rend_encoded_v2_service_descriptor_free(desc_holder_one);
+ rend_encoded_v2_service_descriptor_free(desc_holder_two);
}
#undef NS_SUBMODULE
@@ -620,7 +689,7 @@ test_rend_cache_init(void *data)
tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
done:
- (void)0;
+ rend_cache_free_all();
}
static void
@@ -659,11 +728,11 @@ test_rend_cache_increment_allocation(void *data)
// Test when there are too many allocations
rend_cache_total_allocation = SIZE_MAX-1;
rend_cache_increment_allocation(2);
- tt_int_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
+ tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
// And again
rend_cache_increment_allocation(2);
- tt_int_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
+ tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
done:
(void)0;
@@ -724,7 +793,7 @@ test_rend_cache_failure_intro_lookup(void *data)
tt_assert(entry == ip);
done:
- rend_cache_purge();
+ rend_cache_free_all();
}
static void
@@ -787,7 +856,7 @@ test_rend_cache_clean(void *data)
tt_str_op(key, OP_EQ, "foo2");
done:
- (void)1;
+ rend_cache_free_all();
}
static void
@@ -802,7 +871,7 @@ test_rend_cache_failure_entry_new(void *data)
tt_int_op(digestmap_size(failure->intro_failures), OP_EQ, 0);
done:
- tor_free(failure);
+ rend_cache_failure_entry_free(failure);
}
static void
@@ -870,7 +939,7 @@ test_rend_cache_failure_clean(void *data)
tt_int_op(digestmap_size(failure->intro_failures), OP_EQ, 1);
done:
- (void)0;
+ rend_cache_free_all();
}
static void
@@ -891,7 +960,9 @@ test_rend_cache_failure_remove(void *data)
// There seems to not exist any way of getting rend_cache_failure_remove()
// to fail because of a problem with rend_get_service_id from here
+ rend_cache_free_all();
+ rend_service_descriptor_free(desc);
/* done: */
/* (void)0; */
}
@@ -925,7 +996,7 @@ test_rend_cache_free_all(void *data)
tt_assert(!rend_cache_total_allocation);
done:
- (void)0;
+ rend_cache_free_all();
}
static void
@@ -963,15 +1034,17 @@ test_rend_cache_purge(void *data)
tt_int_op(strmap_size(rend_cache), OP_EQ, 0);
// Deals with existing rend_cache
+ rend_cache_free_all();
rend_cache_init();
our_rend_cache = rend_cache;
rend_cache_purge();
tt_assert(rend_cache);
+ tt_assert(strmap_size(rend_cache) == 0);
tt_assert(rend_cache == our_rend_cache);
done:
- (void)0;
+ rend_cache_free_all();
}
static void
@@ -1002,7 +1075,7 @@ test_rend_cache_failure_intro_add(void *data)
tt_assert(entry);
done:
- rend_cache_purge();
+ rend_cache_free_all();
}
static void
@@ -1012,6 +1085,8 @@ test_rend_cache_intro_failure_note(void *data)
rend_cache_failure_t *fail_entry;
rend_cache_failure_intro_t *entry;
+ rend_cache_init();
+
// Test not found
rend_cache_intro_failure_note(INTRO_POINT_FAILURE_TIMEOUT,
(const uint8_t *)"foo1", "foo2");
@@ -1028,7 +1103,7 @@ test_rend_cache_intro_failure_note(void *data)
tt_int_op(entry->failure_type, OP_EQ, INTRO_POINT_FAILURE_UNREACHABLE);
done:
- rend_cache_purge();
+ rend_cache_free_all();
}
#define NS_SUBMODULE clean_v2_descs_as_dir
@@ -1118,7 +1193,7 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
done:
NS_UNMOCK(hid_serv_responsible_for_desc_id);
- rend_cache_purge();
+ rend_cache_free_all();
}
#undef NS_SUBMODULE
@@ -1128,8 +1203,8 @@ test_rend_cache_entry_allocation(void *data)
{
(void)data;
- int ret;
- rend_cache_entry_t *e;
+ size_t ret;
+ rend_cache_entry_t *e = NULL;
// Handles a null argument
ret = rend_cache_entry_allocation(NULL);
@@ -1138,10 +1213,10 @@ test_rend_cache_entry_allocation(void *data)
// Handles a non-null argument
e = tor_malloc_zero(sizeof(rend_cache_entry_t));
ret = rend_cache_entry_allocation(e);
- tt_int_op(ret, OP_EQ, 88);
+ tt_int_op(ret, OP_GT, sizeof(rend_cache_entry_t));
done:
- (void)0;
+ tor_free(e);
}
static void
@@ -1164,14 +1239,16 @@ test_rend_cache_failure_purge(void *data)
(void)data;
// Handles a null failure cache
+ strmap_free(rend_cache_failure, rend_cache_failure_entry_free_);
rend_cache_failure = NULL;
rend_cache_failure_purge();
+ tt_ptr_op(rend_cache_failure, OP_NE, NULL);
tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
done:
- (void)0;
+ rend_cache_free_all();
}
static void
@@ -1203,7 +1280,9 @@ test_rend_cache_validate_intro_point_failure(void *data)
tt_int_op(smartlist_len(desc->intro_nodes), OP_EQ, 2);
done:
- rend_cache_purge();
+ rend_cache_free_all();
+ rend_service_descriptor_free(desc);
+ tor_free(service_id);
}
struct testcase_t rend_cache_tests[] = {