Fix valgrind memory leak in bug #6814 - Fixes for problems reported by valgrind
authorJeremy Allison <jra@samba.org>
Thu, 15 Oct 2009 23:55:40 +0000 (16:55 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 15 Oct 2009 23:55:40 +0000 (16:55 -0700)
Jeremy.

source3/lib/smbldap.c
source3/passdb/secrets.c
source3/winbindd/idmap_ldap.c

index 47b2208880e1e1d9c53f06098d412d72f73df28b..7287e3d9986a7698a0d40350a1eac71788edac70 100644 (file)
@@ -1054,12 +1054,18 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
        int version;
 
        if (!ldap_state->anonymous && !ldap_state->bind_dn) {
        int version;
 
        if (!ldap_state->anonymous && !ldap_state->bind_dn) {
+               char *bind_dn = NULL;
+               char *bind_secret = NULL;
 
                /* get the default dn and password only if they are not set already */
 
                /* get the default dn and password only if they are not set already */
-               if (!fetch_ldap_pw(&ldap_state->bind_dn, &ldap_state->bind_secret)) {
+               if (!fetch_ldap_pw(&bind_dn, &bind_secret)) {
                        DEBUG(0, ("ldap_connect_system: Failed to retrieve password from secrets.tdb\n"));
                        return LDAP_INVALID_CREDENTIALS;
                }
                        DEBUG(0, ("ldap_connect_system: Failed to retrieve password from secrets.tdb\n"));
                        return LDAP_INVALID_CREDENTIALS;
                }
+               smbldap_set_creds(ldap_state, false, bind_dn, bind_secret);
+               SAFE_FREE(bind_dn);
+               memset(bind_secret, '\0', strlen(bind_secret));
+               SAFE_FREE(bind_secret);
        }
 
        /* removed the sasl_bind_s "EXTERNAL" stuff, as my testsuite 
        }
 
        /* removed the sasl_bind_s "EXTERNAL" stuff, as my testsuite 
index 8b87c2cd4cd5aeacfa9e47f4260b28844e2320ee..29e06623960c4ce6a0a77c19d9827363d74f0450 100644 (file)
@@ -891,6 +891,7 @@ bool fetch_ldap_pw(char **dn, char** pw)
        if (asprintf(&key, "%s/%s", SECRETS_LDAP_BIND_PW, *dn) < 0) {
                SAFE_FREE(*dn);
                DEBUG(0, ("fetch_ldap_pw: asprintf failed!\n"));
        if (asprintf(&key, "%s/%s", SECRETS_LDAP_BIND_PW, *dn) < 0) {
                SAFE_FREE(*dn);
                DEBUG(0, ("fetch_ldap_pw: asprintf failed!\n"));
+               return false;
        }
 
        *pw=(char *)secrets_fetch(key, &size);
        }
 
        *pw=(char *)secrets_fetch(key, &size);
index 3d1dd488d6bb11b55513659a2e2d0d1bf9454f66..375c04a0bf05fa5681a02692e62ba1f64e97fc46 100644 (file)
@@ -131,6 +131,7 @@ static NTSTATUS get_credentials( TALLOC_CTX *mem_ctx,
                        DEBUG(2, ("get_credentials: Failed to lookup ldap "
                                  "bind creds. Using anonymous connection.\n"));
                        anon = True;
                        DEBUG(2, ("get_credentials: Failed to lookup ldap "
                                  "bind creds. Using anonymous connection.\n"));
                        anon = True;
+                       *dn = NULL;
                } else {
                        *dn = talloc_strdup(mem_ctx, user_dn);
                        SAFE_FREE( user_dn );
                } else {
                        *dn = talloc_strdup(mem_ctx, user_dn);
                        SAFE_FREE( user_dn );