Apparently I overlooked something with the ares_save_options() where
it would try to do a malloc(0) when no options of that type needed
to be saved. On most platforms, this was fine because malloc(0) doesn't
actually return NULL, but on AIX it does, so ares_save_options would
return ARES_ENOMEM. Here's the fix ... sorry about that.
-Brad
Index: c-ares/ares_init.c
===================================================================
--- c-ares/ares_init.c (revision 11949)
+++ c-ares/ares_init.c (working copy)
@@ -241,40 +241,49 @@
options->sock_state_cb_data = channel->sock_state_cb_data;
/* Copy servers */
- options->servers =
- malloc(channel->nservers * sizeof(struct server_state));
- if (!options->servers && channel->nservers != 0)
- return ARES_ENOMEM;
- for (i = 0; i < channel->nservers; i++)
- options->servers[i] = channel->servers[i].addr;
+ if (channel->nservers) {
+ options->servers =
+ malloc(channel->nservers * sizeof(struct server_state));
+ if (!options->servers && channel->nservers != 0)
+ return ARES_ENOMEM;
+ for (i = 0; i < channel->nservers; i++)
+ options->servers[i] = channel->servers[i].addr;
+ }
options->nservers = channel->nservers;
/* copy domains */
- options->domains = malloc(channel->ndomains * sizeof(char *));
- if (!options->domains)
- return ARES_ENOMEM;
- for (i = 0; i < channel->ndomains; i++)
- {
- options->ndomains = i;
- options->domains[i] = strdup(channel->domains[i]);
- if (!options->domains[i])
+ if (channel->ndomains) {
+ options->domains = malloc(channel->ndomains * sizeof(char *));
+ if (!options->domains)
return ARES_ENOMEM;
+
+ for (i = 0; i < channel->ndomains; i++)
+ {
+ options->ndomains = i;
+ options->domains[i] = strdup(channel->domains[i]);
+ if (!options->domains[i])
+ return ARES_ENOMEM;
+ }
}
options->ndomains = channel->ndomains;
/* copy lookups */
- options->lookups = strdup(channel->lookups);
- if (!options->lookups)
- return ARES_ENOMEM;
+ if (channel->lookups) {
+ options->lookups = strdup(channel->lookups);
+ if (!options->lookups && channel->lookups)
+ return ARES_ENOMEM;
+ }
/* copy sortlist */
- options->sortlist = malloc(channel->nsort * sizeof(struct apattern));
- if (!options->sortlist)
- return ARES_ENOMEM;
- for (i = 0; i < channel->nsort; i++)
- {
- memcpy(&(options->sortlist[i]), &(channel->sortlist[i]),
- sizeof(struct apattern));
+ if (channel->nsort) {
+ options->sortlist = malloc(channel->nsort * sizeof(struct apattern));
+ if (!options->sortlist)
+ return ARES_ENOMEM;
+ for (i = 0; i < channel->nsort; i++)
+ {
+ memcpy(&(options->sortlist[i]), &(channel->sortlist[i]),
+ sizeof(struct apattern));
+ }
}
options->nsort = channel->nsort;
Received on 2007-09-17