Use non-copying list_append_this_dict

This commit is contained in:
Willem Toorop 2016-03-21 14:56:09 +01:00
parent ba2da45819
commit 90beaaff1d
4 changed files with 43 additions and 38 deletions

View File

@ -320,7 +320,8 @@ local_host_cmp(const void *id1, const void *id2)
return canonical_dname_compare(id1, id2);
}
static void
/** return 0 on success */
static int
add_local_host(getdns_context *context, getdns_dict *address, const char *str)
{
uint8_t host_name[256];
@ -331,7 +332,7 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
getdns_list **addrs;
if (gldns_str2wire_dname_buf(str, host_name, &host_name_len))
return;
return -1;
canonicalize_dname(host_name);
@ -340,7 +341,7 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
if (!(hnas = (host_name_addrs *)GETDNS_XMALLOC(context->mf,
uint8_t, sizeof(host_name_addrs) + host_name_len)))
return;
return -1;
hnas->ipv4addrs = NULL;
hnas->ipv6addrs = NULL;
@ -358,18 +359,23 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
: address_type->data[3] == '6'? &hnas->ipv4addrs : NULL)) {
if (!hnas_found) GETDNS_FREE(context->mf, hnas);
return;
return -1;
}
if (!*addrs && !(*addrs = getdns_list_create_with_context(context))) {
if (!hnas_found) GETDNS_FREE(context->mf, hnas);
return;
return -1;
}
if (_getdns_list_append_dict(*addrs, address) && !hnas_found) {
getdns_list_destroy(*addrs);
GETDNS_FREE(context->mf, hnas);
if (_getdns_list_append_this_dict(*addrs, address)) {
if (!hnas_found) {
getdns_list_destroy(*addrs);
GETDNS_FREE(context->mf, hnas);
}
return -1;
} else if (!hnas_found)
(void)_getdns_rbtree_insert(&context->local_hosts, &hnas->node);
return 0;
}
static getdns_dict *
@ -515,8 +521,8 @@ create_local_hosts(getdns_context *context)
str_addr_dict(context, start_of_word)))
/* Unparseable address */
break; /* skip to next line */
} else
add_local_host(context, address, start_of_word);
} else if (!add_local_host(context, address, start_of_word))
address = NULL;
start_of_word = NULL;
*pos = prev_c;
@ -540,7 +546,8 @@ read_more: ;
if (address) {
/* One last name for this address? */
if (start_of_word && !start_of_line)
add_local_host(context, address, start_of_word);
if (!add_local_host(context, address, start_of_word))
address = NULL;
getdns_dict_destroy(address);
}
}
@ -3634,7 +3641,8 @@ getdns_context_get_upstream_recursive_servers(getdns_context *context,
}
}
if (!r)
r = _getdns_list_append_dict(upstreams, d);
if (!(r = _getdns_list_append_this_dict(upstreams, d)))
d = NULL;
getdns_dict_destroy(d);
}
if (r)

View File

@ -567,8 +567,8 @@ _getdns_fp2rr_list(struct mem_funcs *mf,
continue;
if ((r = _getdns_wire2rr_dict(mf, rr, len, &rr_dict)))
break;
r = _getdns_list_append_dict(rrs, rr_dict);
getdns_dict_destroy(rr_dict);
if ((r = _getdns_list_append_this_dict(rrs, rr_dict)))
getdns_dict_destroy(rr_dict);
}
if (rr)
GETDNS_FREE(*mf, rr);
@ -659,10 +659,9 @@ _getdns_wire2msg_dict_scan(struct mem_funcs *mf,
goto error;
break;
default:
if ((r = _getdns_list_append_dict(
if ((r = _getdns_list_append_this_dict(
sections[section], rr_dict)))
goto error;
getdns_dict_destroy(rr_dict);
break;
}
rr_dict = NULL;

View File

@ -3079,8 +3079,8 @@ static void append_rrs2val_chain_list(getdns_context *ctxt,
&ctxt->mf, &rr->rr_i)))
continue;
(void)_getdns_list_append_dict(val_chain_list, rr_dict);
getdns_dict_destroy(rr_dict);
if (_getdns_list_append_this_dict(val_chain_list, rr_dict))
getdns_dict_destroy(rr_dict);
}
for ( rrsig = rrsig_iter_init(&rrsig_spc, rrset)
; rrsig; rrsig = rrsig_iter_next(rrsig)) {
@ -3098,8 +3098,8 @@ static void append_rrs2val_chain_list(getdns_context *ctxt,
&ctxt->mf, &rrsig->rr_i)))
continue;
(void)_getdns_list_append_dict(val_chain_list, rr_dict);
getdns_dict_destroy(rr_dict);
if (_getdns_list_append_this_dict(val_chain_list, rr_dict))
getdns_dict_destroy(rr_dict);
}
}
}
@ -3130,8 +3130,8 @@ static void append_empty_ds2val_chain_list(
(void) getdns_dict_set_bindata(rdata_dict, "rdata_raw", &bindata);
getdns_dict_destroy(rdata_dict);
(void)_getdns_list_append_dict(val_chain_list, rr_dict);
getdns_dict_destroy(rr_dict);
if (_getdns_list_append_this_dict(val_chain_list, rr_dict))
getdns_dict_destroy(rr_dict);
}
static void check_chain_complete(chain_head *chain)

View File

@ -329,11 +329,10 @@ _getdns_rr_iter2rr_dict(struct mem_funcs *mf, _getdns_rr_iter *i)
_getdns_list_create_with_mf(mf)))
goto rdata_error;
if (_getdns_list_append_dict(
if (_getdns_list_append_this_dict(
repeat_list, repeat_dict))
goto rdata_error;
getdns_dict_destroy(repeat_dict);
repeat_dict = NULL;
}
if (!(repeat_dict =
@ -364,9 +363,8 @@ _getdns_rr_iter2rr_dict(struct mem_funcs *mf, _getdns_rr_iter *i)
if (!repeat_list && !(repeat_list =
_getdns_list_create_with_mf(mf)))
goto rdata_error;
if (_getdns_list_append_dict(repeat_list, repeat_dict))
if (_getdns_list_append_this_dict(repeat_list, repeat_dict))
goto rdata_error;
getdns_dict_destroy(repeat_dict);
repeat_dict = NULL;
}
if (repeat_list) {
@ -549,13 +547,12 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
if (_getdns_dict_set_this_dict(result, "question", rr_dict))
goto error;
rr_dict = NULL;
else rr_dict = NULL;
continue;
}
if (_getdns_list_append_dict(sections[section], rr_dict))
if (_getdns_list_append_this_dict(sections[section], rr_dict))
goto error;
else rr_dict = NULL;
rr_type = gldns_read_uint16(rr_iter->rr_type);
if (section > GLDNS_SECTION_QUESTION &&
@ -589,6 +586,9 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
&rdf_iter_storage, rr_iter)))
continue;
if (!just_addrs)
continue;
bin_size = rdf_iter->nxt - rdf_iter->pos;
bin_data = rdf_iter->pos;
if (!set_dict(&rr_dict, getdns_dict_create_with_context(context)) ||
@ -599,10 +599,11 @@ _getdns_create_reply_dict(getdns_context *context, getdns_network_req *req,
_getdns_dict_set_const_bindata(
rr_dict, "address_data", bin_size, bin_data) ||
(just_addrs && _getdns_list_append_dict(just_addrs, rr_dict))) {
_getdns_list_append_this_dict(just_addrs, rr_dict)) {
goto error;
}
rr_dict = NULL;
}
if (!_getdns_dict_set_this_list(result, "answer",
sections[GLDNS_SECTION_ANSWER]))
@ -951,7 +952,7 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
netreq->tsig_status))
goto error;
}
if (_getdns_list_append_dict(replies_tree, reply)) {
if (_getdns_list_append_this_dict(replies_tree, reply)) {
getdns_dict_destroy(reply);
goto error;
}
@ -961,17 +962,14 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request)
_getdns_create_call_reporting_dict(context,netreq)))
goto error;
if (_getdns_list_append_dict(
if (_getdns_list_append_this_dict(
call_reporting, netreq_debug)) {
getdns_dict_destroy(netreq_debug);
goto error;
}
getdns_dict_destroy(netreq_debug);
}
getdns_dict_destroy(reply);
if (_getdns_list_append_const_bindata(replies_full,
netreq->response_len, netreq->response))
goto error;
@ -1293,8 +1291,8 @@ void _getdns_wire2list(uint8_t *pkt, size_t pkt_len, getdns_list *l)
if (!(rr_dict = _getdns_rr_iter2rr_dict(&l->mf, rr)))
continue;
(void)_getdns_list_append_dict(l, rr_dict);
getdns_dict_destroy(rr_dict);
if (_getdns_list_append_this_dict(l, rr_dict))
getdns_dict_destroy(rr_dict);
}
}