diff --git a/src/tests/dnslib/dnslib_dname_tests.c b/src/tests/dnslib/dnslib_dname_tests.c index 1bbfc519f76a66c6591cd9ea581df5f3324501ef..cde456dbdcb8f9cd4f8346fa1e79f283e80bbca4 100644 --- a/src/tests/dnslib/dnslib_dname_tests.c +++ b/src/tests/dnslib/dnslib_dname_tests.c @@ -186,6 +186,7 @@ static int test_dname_to_str() return (errors == 0); } +/* called by lives_ok */ static int test_faulty_data() { dnslib_dname_t *dname = NULL; @@ -195,8 +196,7 @@ static int test_faulty_data() if (test_domains_bad[i].str != NULL) { dname = dnslib_dname_new_from_str(test_domains_bad[i].str, strlen(test_domains_bad[i].str), NODE_ADDRESS); - } - else { + } else { dname = dnslib_dname_new_from_str(test_domains_bad[i].str, 0, NODE_ADDRESS); } @@ -206,8 +206,9 @@ static int test_faulty_data() dname = dnslib_dname_new_from_wire((uint8_t *)test_domains_bad[i].wire, test_domains_bad[i].size, NODE_ADDRESS); + dnslib_dname_free(&dname); } - return 1; + return 1; //did it get here? success } static int test_dname_compare() diff --git a/src/tests/dnslib/dnslib_node_tests.c b/src/tests/dnslib/dnslib_node_tests.c index c9b01c5f48a2b0e0029fb55341a95ab119d2f6cb..f7f0b6b62bc22191bf255a8126741e9a37ee71b8 100644 --- a/src/tests/dnslib/dnslib_node_tests.c +++ b/src/tests/dnslib/dnslib_node_tests.c @@ -161,6 +161,8 @@ static int test_node_sorting() diag("RRset sorting error"); } } + + dnslib_node_free(&tmp); return (errors == 0); } diff --git a/src/tests/dnslib/dnslib_rdata_tests.c b/src/tests/dnslib/dnslib_rdata_tests.c index 2d4c46a9086426a74735fa1cee31670c34801ffa..4b5011e667a821dcc0f0b0802f193b12db3697c4 100644 --- a/src/tests/dnslib/dnslib_rdata_tests.c +++ b/src/tests/dnslib/dnslib_rdata_tests.c @@ -209,6 +209,7 @@ static int fill_rdata( uint8_t *data, int max_size, uint16_t rrtype, wire_size += dnslib_dname_size(dname); // note("Saved domain name ptr: %p", items[i].dname); } else { + free(dname); items[i].raw_data = pos; pos += size; wire_size += size; @@ -221,8 +222,10 @@ static int fill_rdata( uint8_t *data, int max_size, uint16_t rrtype, int res = dnslib_rdata_set_items(rdata, items, item_count); if (res != 0) { diag("dnslib_rdata_set_items() returned %d.", res); + free(items); return -1; } else { + free(items); return wire_size; } } @@ -544,7 +547,8 @@ static int test_rdata_set_items() ++errors; } errors += check_rdata(data, DNSLIB_MAX_RDATA_WIRE_SIZE, i, rdata); - + +// free(rdata->items[0].dname); dnslib_rdata_free(&rdata); } diff --git a/src/tests/dnslib/dnslib_rrset_tests.c b/src/tests/dnslib/dnslib_rrset_tests.c index fa14098b0ec1790e97763d7069c7b28d6fc2cb85..bac44aa7e9560f757ef9bfc140cfde817f821329 100644 --- a/src/tests/dnslib/dnslib_rrset_tests.c +++ b/src/tests/dnslib/dnslib_rrset_tests.c @@ -36,8 +36,6 @@ enum { TEST_RRSETS = 3 , TEST_RRSIGS = 3}; //void *RRSIG_ADDRESS = (void *)0xDEADBEEF; //void *RRSIG_FIRST = RRSIG_ADDRESS + 10; -static dnslib_rdata_t *rdatas[TEST_RRSETS]; - struct test_rrset { char *owner; uint16_t type; @@ -109,26 +107,22 @@ static const struct test_rrset test_rrsigs[TEST_RRSIGS] = { /* fills test_rrsets with random rdata */ static void create_rdata() { - dnslib_rdata_t *rdata = dnslib_rdata_new(); - dnslib_rdata_item_t item; - item.raw_data = RDATA_ITEM_PTR; - - dnslib_rdata_set_item(rdata, 0, item); - + dnslib_rdata_t *r; for (int i = 0; i < TEST_RRSETS; i++) { - rdatas[i] = dnslib_rdata_new(); + r = dnslib_rdata_new(); dnslib_rdata_item_t item; item.raw_data = RDATA_ITEM_PTR; - dnslib_rdata_set_item(rdata, 0, item); + dnslib_rdata_set_item(r, 0, item); uint8_t data[DNSLIB_MAX_RDATA_WIRE_SIZE]; generate_rdata(data, DNSLIB_MAX_RDATA_WIRE_SIZE); // set items through set_items() and then call set_item() uint16_t rrtype = rand() % DNSLIB_RRTYPE_LAST + 1; - fill_rdata(data, DNSLIB_MAX_RDATA_WIRE_SIZE, rrtype, rdatas[i]); - test_rrsets[i].rdata = rdatas[i]; + // from dnslib_rdata_tests.c + fill_rdata(data, DNSLIB_MAX_RDATA_WIRE_SIZE, rrtype, r); + test_rrsets[i].rdata = r; } } @@ -275,7 +269,7 @@ static int test_rrset_rdata() dnslib_rrset_t *rrset = dnslib_rrset_new(NULL, 0, 0, 0); - dnslib_rdata_t *tmp; + dnslib_rdata_t *r; dnslib_rdata_item_t *item; @@ -283,14 +277,16 @@ static int test_rrset_rdata() { "-2", "9", "2", "10", "1", "5", "8", "4", "6", "7" }; for (int i = 0; i < 10; i++) { - tmp = dnslib_rdata_new(); - item=malloc(sizeof(dnslib_rdata_item_t)); + r = dnslib_rdata_new(); + item=malloc(sizeof(dnslib_rdata_item_t)); item->raw_data = (uint8_t*)test_strings[i]; - dnslib_rdata_set_items(tmp, item, 1); - dnslib_rrset_add_rdata(rrset, tmp); + //following statement creates a copy + dnslib_rdata_set_items(r, item, 1); + dnslib_rrset_add_rdata(rrset, r); + free(item); } - tmp = rrset->rdata; + dnslib_rdata_t *tmp = rrset->rdata; int i = 0; while (tmp->next!=rrset->rdata && !errors) @@ -304,6 +300,18 @@ static int test_rrset_rdata() tmp = tmp->next; } + tmp = rrset->rdata; + + dnslib_rdata_t *next; + + while (tmp->next != rrset->rdata) { + next = tmp->next; + dnslib_rdata_free(&tmp); + tmp = next; + } + + dnslib_rdata_free(&tmp); + dnslib_rrset_free(&rrset); return (errors == 0); @@ -317,15 +325,19 @@ static int test_rrset_rrsigs() dnslib_rdata_t *tmp; + dnslib_dname_t *owner; + + dnslib_rrset_t *rrset; + for (int i = 0; i < TEST_RRSETS; i++) { - dnslib_dname_t *owner = dnslib_dname_new_from_str(test_rrsets[i].owner, + owner = dnslib_dname_new_from_str(test_rrsets[i].owner, strlen(test_rrsets[i].owner), NODE_ADDRESS); if (owner == NULL) { diag("Error creating owner domain name!"); return 0; } - dnslib_rrset_t *rrset = dnslib_rrset_new(owner, test_rrsets[i].type, + rrset = dnslib_rrset_new(owner, test_rrsets[i].type, test_rrsets[i].rclass, test_rrsets[i].ttl); dnslib_rrset_add_rdata(rrset, test_rrsets[i].rdata); @@ -346,8 +358,12 @@ static int test_rrset_rrsigs() errors++; } errors += check_rrset(rrset, i, 0, 1); + dnslib_dname_free(&owner); + dnslib_rrset_free(&rrset); + free(item); + dnslib_rdata_free(&tmp); + dnslib_rrset_free(&rrsig); } - return (errors == 0); }