mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-12-09 12:30:07 +00:00
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.
This commit is contained in:
21
ares_init.c
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user