Bugfix don't grow upstreams memory

upstreams have internal references and cannot be realloc'ed easily
This commit is contained in:
Willem Toorop 2015-11-01 15:23:26 +09:00
parent 35c803208b
commit 8b9041325b
2 changed files with 19 additions and 25 deletions

View File

@ -1,3 +1,6 @@
* 2015-11-??: Version 0.5.1
* Bufix: growing upstreams arrow.
* 2015-10-29: Version 0.5.0 * 2015-10-29: Version 0.5.0
* Native crypto. No ldns dependency anymore. * Native crypto. No ldns dependency anymore.
(ldns still necessary to be able to run tests though) (ldns still necessary to be able to run tests though)

View File

@ -512,16 +512,6 @@ upstreams_create(getdns_context *context, size_t size)
return r; return r;
} }
static getdns_upstreams *
upstreams_resize(getdns_upstreams *upstreams, size_t size)
{
getdns_upstreams *r = (void *) GETDNS_XREALLOC(
upstreams->mf, upstreams, char,
sizeof(getdns_upstreams) +
sizeof(getdns_upstream) * size);
return r;
}
void void
_getdns_upstreams_dereference(getdns_upstreams *upstreams) _getdns_upstreams_dereference(getdns_upstreams *upstreams)
{ {
@ -655,7 +645,7 @@ set_os_defaults(struct getdns_context *context)
FILE *in; FILE *in;
char line[1024], domain[1024]; char line[1024], domain[1024];
char *parse, *token, prev_ch; char *parse, *token, prev_ch;
size_t upstreams_limit = 10, length; size_t upstream_count, length;
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *result; struct addrinfo *result;
getdns_upstream *upstream; getdns_upstream *upstream;
@ -673,8 +663,20 @@ set_os_defaults(struct getdns_context *context)
} }
_getdns_filechg_check(context, context->fchg_resolvconf); _getdns_filechg_check(context, context->fchg_resolvconf);
in = fopen(context->fchg_resolvconf->fn, "r");
if (!in)
return GETDNS_RETURN_GOOD;
upstream_count = 0;
while (fgets(line, (int)sizeof(line), in))
if (strncmp(line, "nameserver", 10) == 0)
upstream_count++;
fclose(in);
fprintf(stderr, "%d\n", (int)upstream_count);
context->suffix = getdns_list_create_with_context(context); context->suffix = getdns_list_create_with_context(context);
context->upstreams = upstreams_create(context, upstreams_limit); context->upstreams = upstreams_create(
context, upstream_count * GETDNS_UPSTREAM_TRANSPORTS);
in = fopen(context->fchg_resolvconf->fn, "r"); in = fopen(context->fchg_resolvconf->fn, "r");
if (!in) if (!in)
@ -735,11 +737,6 @@ set_os_defaults(struct getdns_context *context)
if (!result) if (!result)
continue; continue;
/* Grow array when needed */
if (context->upstreams->count == upstreams_limit)
context->upstreams = upstreams_resize(
context->upstreams, (upstreams_limit *= 2));
upstream = &context->upstreams-> upstream = &context->upstreams->
upstreams[context->upstreams->count++]; upstreams[context->upstreams->count++];
upstream_init(upstream, context->upstreams, result); upstream_init(upstream, context->upstreams, result);
@ -1693,7 +1690,6 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
getdns_return_t r; getdns_return_t r;
size_t count = 0; size_t count = 0;
size_t i; size_t i;
//size_t upstreams_limit;
getdns_upstreams *upstreams; getdns_upstreams *upstreams;
char addrstr[1024], portstr[1024], *eos; char addrstr[1024], portstr[1024], *eos;
struct addrinfo hints; struct addrinfo hints;
@ -1714,8 +1710,8 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
hints.ai_addr = NULL; hints.ai_addr = NULL;
hints.ai_next = NULL; hints.ai_next = NULL;
upstreams = upstreams_create(context, count*3); upstreams = upstreams_create(
//upstreams_limit = count; context, count * GETDNS_UPSTREAM_TRANSPORTS);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
getdns_dict *dict; getdns_dict *dict;
getdns_bindata *address_type; getdns_bindata *address_type;
@ -1785,11 +1781,6 @@ getdns_context_set_upstream_recursive_servers(struct getdns_context *context,
* already exist (in case user has specified TLS port explicitly and * already exist (in case user has specified TLS port explicitly and
* to prevent duplicates) */ * to prevent duplicates) */
/* TODO[TLS]: Grow array when needed. This causes a crash later....
if (upstreams->count == upstreams_limit)
upstreams = upstreams_resize(
upstreams, (upstreams_limit *= 2)); */
upstream = &upstreams->upstreams[upstreams->count]; upstream = &upstreams->upstreams[upstreams->count];
upstream->addr.ss_family = addr.ss_family; upstream->addr.ss_family = addr.ss_family;
upstream_init(upstream, upstreams, ai); upstream_init(upstream, upstreams, ai);