WLDAP32: improve error handling for the bind functions

Dimi Paun dimi at lattica.com
Mon Jul 25 09:46:45 CDT 2005


From: "Hans Leidekker" <hans at it.vu.nl>
>  
> -    credW = strAtoW( cred );
> -    if (!credW) return LDAP_NO_MEMORY;
> +    if (dn) {
> +        dnW = strAtoW( dn );
> +        if (!dnW) return LDAP_NO_MEMORY;
> +    }
> +    if (cred) {
> +        credW = strAtoW( cred );
> +        if (!credW) return LDAP_NO_MEMORY;
> +    }

This leaks memory, if credW fails to allocate.
Something like this would work:

  +    WCHAR *dnW = NULL, *credW = NULL;
  +    int ret = LDAP_NO_MEMORY;
  +
  +    if (dn) {
  +        dnW = strAtoW( dn );
  +        if (!dnW) goto exit;
  +    }
  +    if (cred) {
  +        credW = strAtoW( cred );
  +        if (!credW) goto exit;
  +    }
  + ret = ldap_bindW( ld, dnW, credW, method );
  + exit:
  +    free dnW, credW
  +    return ret;




More information about the wine-devel mailing list