From 008e9a9ecd61e9ef719c00d2a34eb963ecae73a0 Mon Sep 17 00:00:00 2001 From: nordsturm Date: Tue, 29 Mar 2016 16:09:44 +0300 Subject: [PATCH] Fix nsort initialization Author: Alexander Drachevskiy http://c-ares.haxx.se/mail/c-ares-archive-2014-07/0004.shtml http://c-ares.haxx.se/mail/c-ares-archive-2014-07/0014.shtml --- ares_init.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ares_init.c b/ares_init.c index 55d9327e..246aa1d6 100644 --- a/ares_init.c +++ b/ares_init.c @@ -520,13 +520,14 @@ static int init_by_options(ares_channel channel, } /* copy sortlist */ - if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) && - (options->nsort>0)) { - channel->sortlist = ares_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 (options->nsort > 0) { + channel->sortlist = ares_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; }