diff --git a/ares_init.c b/ares_init.c index db1f697..ea425cc 100644 --- a/ares_init.c +++ b/ares_init.c @@ -490,13 +490,16 @@ static int init_by_options(ares_channel channel, } /* copy sortlist */ - if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) && - (options->nsort>0)) { - channel->sortlist = malloc(options->nsort * sizeof(struct apattern)); - if (!channel->sortlist) - return ARES_ENOMEM; - for (i = 0; i < options->nsort; i++) - channel->sortlist[i] = options->sortlist[i]; + if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1)) + { + if (channel->nsort > 0) + { + channel->sortlist = malloc(options->nsort * sizeof(struct apattern)); + if (!channel->sortlist) + return ARES_ENOMEM; + for (i = 0; i < options->nsort; i++) + channel->sortlist[i] = options->sortlist[i]; + } channel->nsort = options->nsort; }