Yay! Segfault resolved. + another little mem leak

So the segfault was on destroying the req->extensions dict.
This dict should have been initialized by dns_req_new, when it copied the extensions dict that it had as an argument.
Though, the argument could have been NULL in which case nothing is copied.
To overcome, I've altered dnsget_dict_copy to initialize the target with NULL when the src was NULL.
This commit is contained in:
Willem Toorop 2013-11-08 15:13:49 -08:00
parent 74fcc3c81b
commit 3827db1ad4
2 changed files with 33 additions and 37 deletions

View File

@ -234,16 +234,17 @@ getdns_dict_create()
getdns_return_t
getdns_dict_copy(struct getdns_dict * srcdict, struct getdns_dict ** dstdict)
{
getdns_return_t retval = GETDNS_RETURN_NO_SUCH_DICT_NAME;
struct getdns_dict_item *item;
char *key;
if (srcdict != NULL && dstdict != NULL) {
if (dstdict == NULL)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
if (srcdict == NULL) {
*dstdict = NULL;
return GETDNS_RETURN_GOOD;
}
*dstdict = getdns_dict_create();
LDNS_RBTREE_FOR(item, struct getdns_dict_item *,
&(srcdict->root))
{
LDNS_RBTREE_FOR(item, struct getdns_dict_item *, &(srcdict->root)) {
key = (char *) item->node.key;
switch (item->dtype) {
case t_bindata:
@ -252,18 +253,15 @@ getdns_dict_copy(struct getdns_dict * srcdict, struct getdns_dict ** dstdict)
break;
case t_dict:
getdns_dict_set_dict(*dstdict, key,
item->data.dict);
getdns_dict_set_dict(*dstdict, key, item->data.dict);
break;
case t_int:
getdns_dict_set_int(*dstdict, key,
item->data.n);
getdns_dict_set_int(*dstdict, key, item->data.n);
break;
case t_list:
getdns_dict_set_list(*dstdict, key,
item->data.list);
getdns_dict_set_list(*dstdict, key, item->data.list);
break;
case t_invalid:
@ -272,10 +270,7 @@ getdns_dict_copy(struct getdns_dict * srcdict, struct getdns_dict ** dstdict)
break;
}
}
retval = GETDNS_RETURN_GOOD;
}
return retval;
return GETDNS_RETURN_GOOD;
} /* getdns_dict_copy */
/*---------------------------------------- getdns_dict_item_free */

View File

@ -44,6 +44,7 @@ this_callbackfn(struct getdns_context_t *this_context,
char *res = getdns_pretty_print_dict(this_response);
fprintf(stdout, "%s", res);
getdns_dict_destroy(this_response);
free(res);
} else if (this_callback_type == GETDNS_CALLBACK_CANCEL)
fprintf(stderr,