ares_dup: clear new channel on failure

If the attempt to transfer IPv6 servers from the old to the new channel
fails, the previous code would still return a channel to the user even though
an error return code was generated.  This makes it likely that users would
leak the channel, so explicitly clear the channel in this case.
pull/31/head
David Drysdale 9 years ago
parent 46bb820be3
commit 970dea47b7
  1. 10
      ares_init.c

@ -307,12 +307,18 @@ int ares_dup(ares_channel *dest, ares_channel src)
}
if (ipv6_nservers) {
rc = ares_get_servers(src, &servers);
if (rc != ARES_SUCCESS)
if (rc != ARES_SUCCESS) {
ares_destroy(*dest);
*dest = NULL;
return rc;
}
rc = ares_set_servers(*dest, servers);
ares_free_data(servers);
if (rc != ARES_SUCCESS)
if (rc != ARES_SUCCESS) {
ares_destroy(*dest);
*dest = NULL;
return rc;
}
}
return ARES_SUCCESS; /* everything went fine */

Loading…
Cancel
Save