Fix memory leaks and double frees (my own code)

This commit is contained in:
Willem Toorop 2014-02-10 15:34:18 +01:00
parent 7984680e70
commit 90edb54f2b
3 changed files with 13 additions and 28 deletions

View File

@ -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); r = getdns_dict_get_bindata(rr_dict, "name", &name);
if (r != GETDNS_RETURN_GOOD) if (r != GETDNS_RETURN_GOOD)
break; break;
owner = ldns_rdf_new( owner = ldns_rdf_new_frm_data(
LDNS_RDF_TYPE_DNAME, name->size, name->data); LDNS_RDF_TYPE_DNAME, name->size, name->data);
if (! owner) { if (! owner) {
r = GETDNS_RETURN_MEMORY_ERROR; 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) if (r != GETDNS_RETURN_GOOD)
break; break;
//r = getdns_dict_get_bindata(rdata, "rdata_raw", &rdata_raw);
r = priv_getdns_dict_get_raw_rdata(rdata, &wire, &wire_size); r = priv_getdns_dict_get_raw_rdata(rdata, &wire, &wire_size);
if (r == GETDNS_RETURN_NO_SUCH_DICT_NAME) { if (r == GETDNS_RETURN_NO_SUCH_DICT_NAME) {
r = priv_getdns_construct_wire_rdata_from_rdata( 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) if (r != GETDNS_RETURN_GOOD)
break; 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; pos = 0;
s = ldns_wire2rdf(*rr, wire, wire_size, &pos); s = ldns_wire2rdf(*rr, wire, wire_size, &pos);
GETDNS_FREE(rr_dict->mf, wire); GETDNS_FREE(rr_dict->mf, wire);
if (s == LDNS_STATUS_OK) if (s == LDNS_STATUS_OK)
return r; return r;
fprintf( stderr, "ldns error: %s (pos: %d)\n"
, ldns_get_errorstr_by_id(s), (int)pos);
r = GETDNS_RETURN_GENERIC_ERROR; r = GETDNS_RETURN_GENERIC_ERROR;
} while (0); } while (0);
ldns_rr_free(*rr); ldns_rr_free(*rr);

View File

@ -116,8 +116,10 @@ getdns_return_t create_root_trustanchor_list(struct getdns_list **tas)
break; break;
} }
r = getdns_list_set_dict(*tas, 0, ta); r = getdns_list_set_dict(*tas, 0, ta);
if (r == GETDNS_RETURN_GOOD) if (r == GETDNS_RETURN_GOOD) {
getdns_dict_destroy(ta);
return r; return r;
}
getdns_list_destroy(*tas); getdns_list_destroy(*tas);
} while(0); } while(0);
@ -213,9 +215,8 @@ this_callbackfn(struct getdns_context *context,
} }
getdns_list_destroy(trust_anchors); getdns_list_destroy(trust_anchors);
} while (0); } while (0);
//printf("%s\n", getdns_pretty_print_dict(response));
getdns_dict_destroy(response); getdns_dict_destroy(response);
(void) event_base_loopexit((struct event_base *)userarg, NULL); /* (void) event_base_loopexit((struct event_base *)userarg, NULL); */
} }
int int
@ -271,8 +272,10 @@ main(int argc, char** argv)
} }
else { else {
/* Call the event loop */ /* Call the event loop */
event_base_dispatch(this_event_base); /* event_base_dispatch(this_event_base); */
// TODO: check the return value above do event_base_loop(this_event_base, EVLOOP_ONCE);
while (0 < getdns_context_get_num_pending_requests(
this_context, NULL));
} }
/* Clean up */ /* Clean up */
getdns_dict_destroy(this_extensions); getdns_dict_destroy(this_extensions);

View File

@ -187,10 +187,9 @@ chase(ldns_dnssec_rrsets *rrset, ldns_dnssec_zone *support,
ldns_dnssec_rrs *rrs; ldns_dnssec_rrs *rrs;
/* Secure by trusted keys? */ /* Secure by trusted keys? */
verifying_keys = ldns_rr_list_new(); s = verify_rrset(rrset, trusted, NULL);
s = verify_rrset(rrset, trusted, verifying_keys);
if (s == 0) if (s == 0)
goto done_free_verifying_keys; return s;
/* No, chase with support records.. /* No, chase with support records..
* Is there a verifying key in the 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); ldns_rr_list_free(support_keys);
done_free_to_validate: done_free_to_validate:
ldns_dnssec_zone_free(to_validate); ldns_dnssec_zone_deep_free(to_validate);
done_free_support: done_free_support:
ldns_dnssec_zone_free(support); ldns_dnssec_zone_deep_free(support);
done_free_trusted: done_free_trusted:
ldns_rr_list_deep_free(trusted); ldns_rr_list_deep_free(trusted);
return r; return r;