[PATCH 1/2] dnsapi: migrating to res_nquery (split resend)

Hans Leidekker hans at codeweavers.com
Tue Jan 12 05:06:15 CST 2016


On Mon, 2016-01-11 at 22:07 +0300, Donat Enikeev wrote:
> -static void initialise_resolver( void )
> +static res_state initialise_resolver( void )
>  {
> -    if ((_res.options & RES_INIT) == 0)
> -        res_init();
> +    res_state dns_res_state = NULL;

No need to initialize this variable. Why the dns_ prefix on local variables?

> +    if ( !(dns_res_state = heap_alloc_zero(sizeof(struct __res_state))) )
> +        return NULL;
> +
> +    res_ninit(dns_res_state);
> +
> +    return dns_res_state;
>  }

> @@ -706,6 +719,7 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser
>  {
>      DNS_STATUS ret = DNS_ERROR_RCODE_NOT_IMPLEMENTED;
>  #ifdef HAVE_RESOLV
> +    res_state dns_res_state;
>  
>      TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_a(name), dns_type_to_str( type ),
>             options, servers, result, reserved );
> @@ -713,13 +727,15 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser
>      if (!name || !result)
>          return ERROR_INVALID_PARAMETER;
>  
> -    initialise_resolver();
> -    _res.options |= dns_map_options( options );
> +    dns_res_state = initialise_resolver();
> +    if ( !dns_res_state ) return ERROR_NOT_ENOUGH_MEMORY;
>  
> -    if (servers && (ret = dns_set_serverlist( servers )))
> +    dns_res_state->options |= dns_map_options( options );
> +
> +    if (servers && (ret = dns_set_serverlist( dns_res_state, servers )))
>          return ret;

You are leaking dns_res_state here.
 
> @@ -824,8 +842,9 @@ DNS_STATUS WINAPI DnsQueryConfig( DNS_CONFIG_TYPE config, DWORD flag, PCWSTR ada
>      case DnsConfigDnsServerList:
>      {
>  #ifdef HAVE_RESOLV
> -        initialise_resolver();
> -        ret = dns_get_serverlist( buffer, len );
> +        res_state dns_res_state = initialise_resolver();
> +        ret = dns_get_serverlist( dns_res_state, buffer, len );
> +        heap_free(dns_res_state);

You should check the return value of initialise_resolver() here too.





More information about the wine-devel mailing list