waffle

user and group backend daemon
git clone git://git.2f30.org/waffle
Log | Files | Refs | LICENSE

commit 9f2cfe16d663b248056b82b1d8ed577b02f6cabe
parent a94cc77e09b510be0ab51beb11b2bc51dec36719
Author: sin <sin@2f30.org>
Date:   Wed, 11 Mar 2015 18:37:34 +0000

Properly unwind resources in ldap init()

Diffstat:
Mldap.c | 16++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ldap.c b/ldap.c @@ -139,38 +139,41 @@ init(void) return -1; if (ldap_conf.version != 3) { logwarn("unsupported LDAP version: %d\n", ldap_conf.version); - goto out; + goto out1; } if (ldap_conf.uri) { r = ldap_initialize(&ld, ldap_conf.uri); if (r != LDAP_SUCCESS) { logwarn("ldap_initialize: %s\n", strerror(errno)); - goto out; + goto out1; } } else if (ldap_conf.host) { ld = ldap_init(ldap_conf.host, ldap_conf.port); if (!ld) { logwarn("ldap_init: %s\n", strerror(errno)); - goto out; + goto out1; } } r = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version); if (r != LDAP_SUCCESS) { logwarn("ldap_set_option: %s\n", ldap_err2string(r)); - goto out; + goto out2; } r = ldap_bind_s(ld, ldap_conf.rootbinddn, ldap_conf.bindpw, LDAP_AUTH_SIMPLE); if (r != LDAP_SUCCESS) { logwarn("ldap_simple_bind_s: %s\n", ldap_err2string(r)); - goto out; + goto out2; } return 0; -out: +out2: + ldap_destroy(ld); + ld = NULL; +out1: free_config(); return -1; } @@ -180,6 +183,7 @@ term(void) { if (ld) { ldap_unbind(ld); + ldap_destroy(ld); ld = NULL; } free_config();