Correcting leaks in tests
A couple of testcases did not free its `match_entry` allocations, which triggers leak indications. Visible when build and run using the leak sanitizer, i.e `CFLAGS="-fno-omit-frame-pointer -fsanitize=leak" cmake ..`
This commit is contained in:
parent
b13dc8aa6e
commit
9c8feff07f
3 changed files with 27 additions and 5 deletions
|
@ -29,14 +29,13 @@ START_TEST (test_hosts)
|
||||||
r3_tree_compile(n, &err);
|
r3_tree_compile(n, &err);
|
||||||
ck_assert(err == NULL);
|
ck_assert(err == NULL);
|
||||||
|
|
||||||
|
|
||||||
entry = match_entry_create("/foo");
|
entry = match_entry_create("/foo");
|
||||||
entry->host.base = host0;
|
entry->host.base = host0;
|
||||||
entry->host.len = strlen(host0);
|
entry->host.len = strlen(host0);
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri0);
|
ck_assert(matched_route->data == &uri0);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->host.base = "www.bar.com";
|
entry->host.base = "www.bar.com";
|
||||||
|
@ -44,19 +43,21 @@ START_TEST (test_hosts)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri1);
|
ck_assert(matched_route->data == &uri1);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->host.base = "bar.com";
|
entry->host.base = "bar.com";
|
||||||
entry->host.len = strlen("bar.com");
|
entry->host.len = strlen("bar.com");
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->host.base = ".bar.com";
|
entry->host.base = ".bar.com";
|
||||||
entry->host.len = strlen(".bar.com");
|
entry->host.len = strlen(".bar.com");
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->host.base = "a.bar.com";
|
entry->host.base = "a.bar.com";
|
||||||
|
@ -64,6 +65,7 @@ START_TEST (test_hosts)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri1);
|
ck_assert(matched_route->data == &uri1);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
r3_tree_free(n);
|
r3_tree_free(n);
|
||||||
}
|
}
|
||||||
|
@ -88,4 +90,3 @@ int main (int argc, char *argv[]) {
|
||||||
srunner_free(runner);
|
srunner_free(runner);
|
||||||
return number_failed;
|
return number_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,43 +34,51 @@ START_TEST (test_http_scheme)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri0);
|
ck_assert(matched_route->data == &uri0);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/foo");
|
entry = match_entry_create("/foo");
|
||||||
entry->http_scheme = SCHEME_HTTP;
|
entry->http_scheme = SCHEME_HTTP;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri0);
|
ck_assert(matched_route->data == &uri0);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->http_scheme = SCHEME_HTTP;
|
entry->http_scheme = SCHEME_HTTP;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->http_scheme = SCHEME_HTTPS;
|
entry->http_scheme = SCHEME_HTTPS;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri1);
|
ck_assert(matched_route->data == &uri1);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->http_scheme = SCHEME_HTTP;
|
entry->http_scheme = SCHEME_HTTP;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri2);
|
ck_assert(matched_route->data == &uri2);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->http_scheme = SCHEME_HTTPS;
|
entry->http_scheme = SCHEME_HTTPS;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri2);
|
ck_assert(matched_route->data == &uri2);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
r3_tree_free(n);
|
r3_tree_free(n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ START_TEST (test_remote_addrs)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri0);
|
ck_assert(matched_route->data == &uri0);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->remote_addr.base = "127.0.0.1";
|
entry->remote_addr.base = "127.0.0.1";
|
||||||
|
@ -49,13 +50,14 @@ START_TEST (test_remote_addrs)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri1);
|
ck_assert(matched_route->data == &uri1);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->remote_addr.base = "127.0.0.2";
|
entry->remote_addr.base = "127.0.0.2";
|
||||||
entry->remote_addr.len = sizeof("127.0.0.2") - 1;
|
entry->remote_addr.len = sizeof("127.0.0.2") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->remote_addr.base = "127.0.0.1";
|
entry->remote_addr.base = "127.0.0.1";
|
||||||
|
@ -63,6 +65,7 @@ START_TEST (test_remote_addrs)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri2);
|
ck_assert(matched_route->data == &uri2);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->remote_addr.base = "127.0.0.2";
|
entry->remote_addr.base = "127.0.0.2";
|
||||||
|
@ -70,18 +73,21 @@ START_TEST (test_remote_addrs)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri2);
|
ck_assert(matched_route->data == &uri2);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->remote_addr.base = "127.0.1.2";
|
entry->remote_addr.base = "127.0.1.2";
|
||||||
entry->remote_addr.len = sizeof("127.0.1.2") - 1;
|
entry->remote_addr.len = sizeof("127.0.1.2") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/boo");
|
entry = match_entry_create("/boo");
|
||||||
entry->remote_addr.base = "127.0.1.333"; // invalid ip address
|
entry->remote_addr.base = "127.0.1.333"; // invalid ip address
|
||||||
entry->remote_addr.len = sizeof("127.0.1.333") - 1;
|
entry->remote_addr.len = sizeof("127.0.1.333") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
r3_tree_free(n);
|
r3_tree_free(n);
|
||||||
}
|
}
|
||||||
|
@ -139,18 +145,21 @@ START_TEST (test_remote_addrs_ipv6)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri0);
|
ck_assert(matched_route->data == &uri0);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/foo");
|
entry = match_entry_create("/foo");
|
||||||
entry->remote_addr.base = "fe80:fe80::2";
|
entry->remote_addr.base = "fe80:fe80::2";
|
||||||
entry->remote_addr.len = sizeof("fe80:fe80::2") - 1;
|
entry->remote_addr.len = sizeof("fe80:fe80::2") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/foo");
|
entry = match_entry_create("/foo");
|
||||||
entry->remote_addr.base = "fe88:fe80::1";
|
entry->remote_addr.base = "fe88:fe80::1";
|
||||||
entry->remote_addr.len = sizeof("fe88:fe80::1") - 1;
|
entry->remote_addr.len = sizeof("fe88:fe80::1") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->remote_addr.base = "fe80:fe80::1";
|
entry->remote_addr.base = "fe80:fe80::1";
|
||||||
|
@ -158,12 +167,14 @@ START_TEST (test_remote_addrs_ipv6)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri1);
|
ck_assert(matched_route->data == &uri1);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/bar");
|
entry = match_entry_create("/bar");
|
||||||
entry->remote_addr.base = "fe88:fe80::1";
|
entry->remote_addr.base = "fe88:fe80::1";
|
||||||
entry->remote_addr.len = sizeof("fe88:fe80::1") - 1;
|
entry->remote_addr.len = sizeof("fe88:fe80::1") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/goo");
|
entry = match_entry_create("/goo");
|
||||||
entry->remote_addr.base = "::1";
|
entry->remote_addr.base = "::1";
|
||||||
|
@ -171,12 +182,14 @@ START_TEST (test_remote_addrs_ipv6)
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route != NULL);
|
ck_assert(matched_route != NULL);
|
||||||
ck_assert(matched_route->data == &uri2);
|
ck_assert(matched_route->data == &uri2);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
entry = match_entry_create("/goo");
|
entry = match_entry_create("/goo");
|
||||||
entry->remote_addr.base = "::2";
|
entry->remote_addr.base = "::2";
|
||||||
entry->remote_addr.len = sizeof("::2") - 1;
|
entry->remote_addr.len = sizeof("::2") - 1;
|
||||||
matched_route = r3_tree_match_route(n, entry);
|
matched_route = r3_tree_match_route(n, entry);
|
||||||
ck_assert(matched_route == NULL);
|
ck_assert(matched_route == NULL);
|
||||||
|
match_entry_free(entry);
|
||||||
|
|
||||||
r3_tree_free(n);
|
r3_tree_free(n);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue