From 90edb54f2bfcc1fc8cf527073683f33541fd97a5 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Mon, 10 Feb 2014 15:34:18 +0100 Subject: [PATCH] Fix memory leaks and double frees (my own code) --- src/rr-dict.c | 19 +------------------ src/test/tests_dnssec.c | 13 ++++++++----- src/validate_dnssec.c | 9 ++++----- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/rr-dict.c b/src/rr-dict.c index 6a218168..bd89fc22 100644 --- a/src/rr-dict.c +++ b/src/rr-dict.c @@ -1186,7 +1186,7 @@ priv_getdns_create_rr_from_dict(struct getdns_dict *rr_dict, ldns_rr **rr) r = getdns_dict_get_bindata(rr_dict, "name", &name); if (r != GETDNS_RETURN_GOOD) break; - owner = ldns_rdf_new( + owner = ldns_rdf_new_frm_data( LDNS_RDF_TYPE_DNAME, name->size, name->data); if (! owner) { r = GETDNS_RETURN_MEMORY_ERROR; @@ -1203,7 +1203,6 @@ priv_getdns_create_rr_from_dict(struct getdns_dict *rr_dict, ldns_rr **rr) if (r != GETDNS_RETURN_GOOD) break; - //r = getdns_dict_get_bindata(rdata, "rdata_raw", &rdata_raw); r = priv_getdns_dict_get_raw_rdata(rdata, &wire, &wire_size); if (r == GETDNS_RETURN_NO_SUCH_DICT_NAME) { r = priv_getdns_construct_wire_rdata_from_rdata( @@ -1211,27 +1210,11 @@ priv_getdns_create_rr_from_dict(struct getdns_dict *rr_dict, ldns_rr **rr) } if (r != GETDNS_RETURN_GOOD) break; -#if 0 - fprintf(stderr, "wire_size: %d\n", (int)wire_size); - fprintf(stderr, "wire data: "); - for (size_t i = 0; i < wire_size; i++) { - if (i) { - if (i % 24 == 0) - fprintf(stderr, "\n "); - else if (i % 4 == 0) - fprintf(stderr, " "); - } - fprintf(stderr, "%.2x", wire[i]); - } - fprintf(stderr, "\n"); -#endif pos = 0; s = ldns_wire2rdf(*rr, wire, wire_size, &pos); GETDNS_FREE(rr_dict->mf, wire); if (s == LDNS_STATUS_OK) return r; - fprintf( stderr, "ldns error: %s (pos: %d)\n" - , ldns_get_errorstr_by_id(s), (int)pos); r = GETDNS_RETURN_GENERIC_ERROR; } while (0); ldns_rr_free(*rr); diff --git a/src/test/tests_dnssec.c b/src/test/tests_dnssec.c index ef843fd2..8bc20787 100644 --- a/src/test/tests_dnssec.c +++ b/src/test/tests_dnssec.c @@ -116,8 +116,10 @@ getdns_return_t create_root_trustanchor_list(struct getdns_list **tas) break; } r = getdns_list_set_dict(*tas, 0, ta); - if (r == GETDNS_RETURN_GOOD) + if (r == GETDNS_RETURN_GOOD) { + getdns_dict_destroy(ta); return r; + } getdns_list_destroy(*tas); } while(0); @@ -213,9 +215,8 @@ this_callbackfn(struct getdns_context *context, } getdns_list_destroy(trust_anchors); } while (0); - //printf("%s\n", getdns_pretty_print_dict(response)); getdns_dict_destroy(response); - (void) event_base_loopexit((struct event_base *)userarg, NULL); + /* (void) event_base_loopexit((struct event_base *)userarg, NULL); */ } int @@ -271,8 +272,10 @@ main(int argc, char** argv) } else { /* Call the event loop */ - event_base_dispatch(this_event_base); - // TODO: check the return value above + /* event_base_dispatch(this_event_base); */ + do event_base_loop(this_event_base, EVLOOP_ONCE); + while (0 < getdns_context_get_num_pending_requests( + this_context, NULL)); } /* Clean up */ getdns_dict_destroy(this_extensions); diff --git a/src/validate_dnssec.c b/src/validate_dnssec.c index 58b939e7..d81fd84f 100644 --- a/src/validate_dnssec.c +++ b/src/validate_dnssec.c @@ -187,10 +187,9 @@ chase(ldns_dnssec_rrsets *rrset, ldns_dnssec_zone *support, ldns_dnssec_rrs *rrs; /* Secure by trusted keys? */ - verifying_keys = ldns_rr_list_new(); - s = verify_rrset(rrset, trusted, verifying_keys); + s = verify_rrset(rrset, trusted, NULL); if (s == 0) - goto done_free_verifying_keys; + return s; /* No, chase with support records.. * Is there a verifying key in the support records? @@ -318,9 +317,9 @@ getdns_validate_dnssec(struct getdns_list *records_to_validate, ldns_rr_list_free(support_keys); done_free_to_validate: - ldns_dnssec_zone_free(to_validate); + ldns_dnssec_zone_deep_free(to_validate); done_free_support: - ldns_dnssec_zone_free(support); + ldns_dnssec_zone_deep_free(support); done_free_trusted: ldns_rr_list_deep_free(trusted); return r;