init_by_options: don't copy an empty sortlist

If there aren't any sort items to copy, don't bother. Without this
little precaution it would do a malloc(0) which causes undefined
behaviors and is frowned upon by curl's memdebug-system.
pull/1/head
Daniel Stenberg 14 years ago
parent 679c1032cb
commit 803e2a28b7
  1. 21
      ares_init.c

@ -498,18 +498,15 @@ static int init_by_options(ares_channel channel,
}
/* copy sortlist */
if ((optmask & ARES_OPT_SORTLIST) && channel->nsort == -1)
{
channel->sortlist = malloc(options->nsort * sizeof(struct apattern));
if (!channel->sortlist)
return ARES_ENOMEM;
for (i = 0; i < options->nsort; i++)
{
memcpy(&(channel->sortlist[i]), &(options->sortlist[i]),
sizeof(struct apattern));
}
channel->nsort = options->nsort;
}
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];
channel->nsort = options->nsort;
}
channel->optmask = optmask;

Loading…
Cancel
Save