From 970dea47b78848435f29fecbed2605931d6cb980 Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Wed, 23 Dec 2015 12:28:16 +0000 Subject: [PATCH] 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. --- ares_init.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ares_init.c b/ares_init.c index a0ba1ee2..c98ae78a 100644 --- a/ares_init.c +++ b/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 */