diff --git a/src/context.c b/src/context.c index 83d691f3..88d98725 100644 --- a/src/context.c +++ b/src/context.c @@ -676,7 +676,7 @@ getdns_return_t getdns_context_set_namespaces(struct getdns_context *context, size_t namespace_count, getdns_namespace_t *namespaces) { - int i; + size_t i; RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER); if (namespace_count == 0 || namespaces == NULL) { diff --git a/src/convert.c b/src/convert.c index c9a07e34..d34a4ebc 100644 --- a/src/convert.c +++ b/src/convert.c @@ -185,7 +185,6 @@ getdns_display_ip_address(const struct getdns_bindata return NULL; } -const char *getdns_get_errorstr_by_id(uint16_t err); getdns_return_t getdns_strerror(getdns_return_t err, char *buf, size_t buflen) { diff --git a/src/dict.c b/src/dict.c index 5c520987..8e3a2a93 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1,8 +1,7 @@ /** * - * getdns list management functions, note that the internal storage is - * accomplished via the libc binary search tree implementation so your - * pointer foo needs to be keen to digest some of the internal semantics + * getdns dict management functions, note that the internal storage is + * accomplished via an ldns_rbtree_t * * Interfaces originally taken from the getdns API description pseudo implementation. * @@ -68,7 +67,7 @@ getdns_dict_find_and_add(struct getdns_dict *dict, const char *key) ldns_rbtree_search(&(dict->root), key); if (!item) { - /* tsearch will add a node automatically for us */ + /* add a node */ item = GETDNS_MALLOC(dict->mf, struct getdns_dict_item); item->node.key = getdns_strdup(&dict->mf, key); item->data.n = 0; @@ -500,7 +499,7 @@ priv_getdns_bindata_is_dname(struct getdns_bindata *bindata) { size_t i = 0, n_labels = 0; while (i < bindata->size) { - i += bindata->data[i] + 1; + i += ((size_t)bindata->data[i]) + 1; n_labels++; } return i == bindata->size && n_labels > 1 && diff --git a/src/general.c b/src/general.c index 0f5add72..86f7a380 100644 --- a/src/general.c +++ b/src/general.c @@ -101,7 +101,7 @@ ub_local_resolve_timeout(void *arg) ub_resolve_callback(cb_data->netreq, cb_data->err, cb_data->ub_res); /* cleanup the state */ - free(cb_data); + GETDNS_FREE(dnsreq->my_mf, cb_data); } void priv_getdns_call_user_callback(getdns_dns_req *dns_req, @@ -174,8 +174,7 @@ ub_resolve_callback(void* arg, int err, struct ub_result* ub_res) * netreqs need to be issued and some resolve immediately vs. not. */ getdns_dns_req *dnsreq = netreq->owner; - netreq_cb_data *cb_data = - (netreq_cb_data *) malloc(sizeof(netreq_cb_data)); + netreq_cb_data *cb_data = GETDNS_MALLOC(dnsreq->my_mf, netreq_cb_data); cb_data->netreq = netreq; cb_data->err = err; cb_data->ub_res = ub_res; diff --git a/src/request-internal.c b/src/request-internal.c index b13ae197..8e6590ee 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -43,11 +43,10 @@ network_req_free(getdns_network_req * net_req) if (!net_req) { return; } - struct getdns_context *context = net_req->owner->context; if (net_req->result) { ldns_pkt_free(net_req->result); } - GETDNS_FREE(context->mf, net_req); + GETDNS_FREE(net_req->owner->my_mf, net_req); } getdns_network_req * @@ -56,8 +55,7 @@ network_req_new(getdns_dns_req * owner, uint16_t request_class, struct getdns_dict *extensions) { - struct getdns_context *context = owner->context; - getdns_network_req *net_req = GETDNS_MALLOC( context->mf + getdns_network_req *net_req = GETDNS_MALLOC( owner->my_mf , getdns_network_req); if (!net_req) { return NULL; @@ -103,9 +101,9 @@ dns_req_free(getdns_dns_req * req) getdns_context_clear_timeout(context, req->trans_id); /* free strduped name */ - free(req->name); + GETDNS_FREE(req->my_mf, req->name); - GETDNS_FREE(context->mf, req); + GETDNS_FREE(req->my_mf, req); } /* create a new dns req to be submitted */ @@ -121,8 +119,8 @@ dns_req_new(struct getdns_context *context, if (result == NULL) { return NULL; } - - result->name = strdup(name); + result->my_mf = context->mf; + result->name = getdns_strdup(&(result->my_mf), name); result->context = context; result->canceled = 0; result->current_req = NULL; diff --git a/src/types-internal.h b/src/types-internal.h index 73d80e40..c12bedd4 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -101,6 +101,28 @@ struct getdns_context; struct getdns_dns_req; struct getdns_network_req; + +#define MF_PLAIN ((void *)&plain_mem_funcs_user_arg) +extern void *plain_mem_funcs_user_arg; + +typedef union { + struct { + void *(*malloc)(size_t); + void *(*realloc)(void *, size_t); + void (*free)(void *); + } pln; + struct { + void *(*malloc)(void *userarg, size_t); + void *(*realloc)(void *userarg, void *, size_t); + void (*free)(void *userarg, void *); + } ext; + } mf_union; + +struct mem_funcs { + void *mf_arg; + mf_union mf; +}; + typedef enum network_req_state_enum { NET_REQ_NOT_SENT, @@ -183,29 +205,11 @@ typedef struct getdns_dns_req /* dnssec status */ int return_dnssec_status; + /* mem funcs */ + struct mem_funcs my_mf; + } getdns_dns_req; -#define MF_PLAIN ((void *)&plain_mem_funcs_user_arg) -extern void *plain_mem_funcs_user_arg; - -typedef union { - struct { - void *(*malloc)(size_t); - void *(*realloc)(void *, size_t); - void (*free)(void *); - } pln; - struct { - void *(*malloc)(void *userarg, size_t); - void *(*realloc)(void *userarg, void *, size_t); - void (*free)(void *userarg, void *); - } ext; - } mf_union; - -struct mem_funcs { - void *mf_arg; - mf_union mf; -}; - #define GETDNS_XMALLOC(obj, type, count) \ ((obj).mf_arg == MF_PLAIN \ ? ((type *)(*(obj).mf.pln.malloc)( (count)*sizeof(type))) \