@@ -266,7 +266,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
266266 which is most of them */
267267 rc = ares_save_options (src , & opts , & optmask );
268268 if (rc )
269+ {
270+ ares_destroy_options (& opts );
269271 return rc ;
272+ }
270273
271274 /* Then create the new channel with those options */
272275 rc = ares_init_options (dest , & opts , optmask );
@@ -1158,20 +1161,24 @@ static int init_by_resolv_conf(ares_channel channel)
11581161 FILE * fp ;
11591162 size_t linesize ;
11601163 int error ;
1164+ int update_domains ;
11611165
11621166 /* Don't read resolv.conf and friends if we don't have to */
11631167 if (ARES_CONFIG_CHECK (channel ))
11641168 return ARES_SUCCESS ;
11651169
1170+ /* Only update search domains if they're not already specified */
1171+ update_domains = (channel -> ndomains == -1 );
1172+
11661173 fp = fopen (PATH_RESOLV_CONF , "r" );
11671174 if (fp ) {
11681175 while ((status = ares__read_line (fp , & line , & linesize )) == ARES_SUCCESS )
11691176 {
1170- if ((p = try_config (line , "domain" , ';' )))
1177+ if ((p = try_config (line , "domain" , ';' )) && update_domains )
11711178 status = config_domain (channel , p );
11721179 else if ((p = try_config (line , "lookup" , ';' )) && !channel -> lookups )
11731180 status = config_lookup (channel , p , "bind" , "file" );
1174- else if ((p = try_config (line , "search" , ';' )))
1181+ else if ((p = try_config (line , "search" , ';' )) && update_domains )
11751182 status = set_search (channel , p );
11761183 else if ((p = try_config (line , "nameserver" , ';' )) &&
11771184 channel -> nservers == -1 )
@@ -1410,7 +1417,7 @@ static int init_by_defaults(ares_channel channel)
14101417 goto error ;
14111418 }
14121419
1413- } WHILE_FALSE ;
1420+ } while ( res != 0 ) ;
14141421
14151422 dot = strchr (hostname , '.' );
14161423 if (dot ) {
0 commit comments