@@ -266,7 +266,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
266
266
which is most of them */
267
267
rc = ares_save_options (src , & opts , & optmask );
268
268
if (rc )
269
+ {
270
+ ares_destroy_options (& opts );
269
271
return rc ;
272
+ }
270
273
271
274
/* Then create the new channel with those options */
272
275
rc = ares_init_options (dest , & opts , optmask );
@@ -1158,20 +1161,24 @@ static int init_by_resolv_conf(ares_channel channel)
1158
1161
FILE * fp ;
1159
1162
size_t linesize ;
1160
1163
int error ;
1164
+ int update_domains ;
1161
1165
1162
1166
/* Don't read resolv.conf and friends if we don't have to */
1163
1167
if (ARES_CONFIG_CHECK (channel ))
1164
1168
return ARES_SUCCESS ;
1165
1169
1170
+ /* Only update search domains if they're not already specified */
1171
+ update_domains = (channel -> ndomains == -1 );
1172
+
1166
1173
fp = fopen (PATH_RESOLV_CONF , "r" );
1167
1174
if (fp ) {
1168
1175
while ((status = ares__read_line (fp , & line , & linesize )) == ARES_SUCCESS )
1169
1176
{
1170
- if ((p = try_config (line , "domain" , ';' )))
1177
+ if ((p = try_config (line , "domain" , ';' )) && update_domains )
1171
1178
status = config_domain (channel , p );
1172
1179
else if ((p = try_config (line , "lookup" , ';' )) && !channel -> lookups )
1173
1180
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 )
1175
1182
status = set_search (channel , p );
1176
1183
else if ((p = try_config (line , "nameserver" , ';' )) &&
1177
1184
channel -> nservers == -1 )
@@ -1410,7 +1417,7 @@ static int init_by_defaults(ares_channel channel)
1410
1417
goto error ;
1411
1418
}
1412
1419
1413
- } WHILE_FALSE ;
1420
+ } while ( res != 0 ) ;
1414
1421
1415
1422
dot = strchr (hostname , '.' );
1416
1423
if (dot ) {
0 commit comments