From f746c03828d00781843af45584ef15fe5d1442c3 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 23 Oct 2015 03:01:38 -0500 Subject: Fix memory leak on bind failure Fix minor issues with comments (cherry picked from commit 3fdd5c964ae9d1be5d17feef88a421771fe884cd) --- src/libtdeldap.cpp | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp index 11b0150..1e2678c 100644 --- a/src/libtdeldap.cpp +++ b/src/libtdeldap.cpp @@ -317,12 +317,16 @@ int LDAPManager::bind(TQString* errstr) { } } } - // clean up + // Clean up ldap_msgfree(msg); // All done! ldap_unbind_ext_s(ldapconn, NULL, NULL); } + else { + // Clean up + ldap_unbind_ext_s(ldapconn, NULL, NULL); + } } } @@ -654,8 +658,8 @@ LDAPUserInfoList LDAPManager::users(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { users.append(parseLDAPUserRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); if (mretcode) *mretcode = 0; @@ -732,8 +736,8 @@ LDAPUserInfoList LDAPManager::users(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { users.append(parseLDAPUserRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); } while (morePages); @@ -765,8 +769,8 @@ LDAPUserInfo LDAPManager::getUserByDistinguishedName(TQString dn) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { userinfo = parseLDAPUserRecord(entry); } - - // clean up + + // Clean up ldap_msgfree(msg); return userinfo; @@ -796,8 +800,8 @@ LDAPGroupInfo LDAPManager::getGroupByDistinguishedName(TQString dn, TQString *er for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { groupinfo = parseLDAPGroupRecord(entry); } - - // clean up + + // Clean up ldap_msgfree(msg); return groupinfo; @@ -2204,8 +2208,8 @@ LDAPGroupInfoList LDAPManager::groups(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { groups.append(parseLDAPGroupRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); if (mretcode) *mretcode = 0; @@ -2282,8 +2286,8 @@ LDAPGroupInfoList LDAPManager::groups(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { groups.append(parseLDAPGroupRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); } while (morePages); @@ -2325,8 +2329,8 @@ LDAPMachineInfoList LDAPManager::machines(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { machines.append(parseLDAPMachineRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); if (mretcode) *mretcode = 0; @@ -2403,8 +2407,8 @@ LDAPMachineInfoList LDAPManager::machines(int* mretcode, TQString *errstr) { for(entry = ldap_first_entry(m_ldap, msg); entry != NULL; entry = ldap_next_entry(m_ldap, entry)) { machines.append(parseLDAPMachineRecord(entry)); } - - // clean up + + // Clean up ldap_msgfree(msg); } while (morePages); @@ -2486,7 +2490,7 @@ LDAPServiceInfoList LDAPManager::machineServices(TQString machine_dn, int* mretc } } - // clean up + // Clean up ldap_msgfree(msg); if (mretcode) *mretcode = 0; @@ -2684,7 +2688,7 @@ TQString LDAPManager::getRealmCAMaster(TQString* errstr) { } } - // clean up + // Clean up ldap_msgfree(msg); return realmCAMaster; @@ -2763,7 +2767,7 @@ int LDAPManager::moveKerberosEntries(TQString newSuffix, TQString* errstr) { } } - // clean up + // Clean up ldap_msgfree(msg); return 0; @@ -3048,7 +3052,7 @@ LDAPTDEBuiltinsInfo LDAPManager::getTDEBuiltinMappings(TQString *errstr) { builtininfo = parseLDAPTDEBuiltinsRecord(entry); } - // clean up + // Clean up ldap_msgfree(msg); return builtininfo; @@ -3084,7 +3088,7 @@ LDAPMasterReplicationInfo LDAPManager::getLDAPMasterReplicationSettings(TQString } } - // clean up + // Clean up ldap_msgfree(msg); // Set OpenLDAP defaults @@ -3103,7 +3107,7 @@ LDAPMasterReplicationInfo LDAPManager::getLDAPMasterReplicationSettings(TQString replicationinfo = parseLDAPMasterReplicationRecord(replicationinfo, entry); } - // clean up + // Clean up ldap_msgfree(msg); return replicationinfo; @@ -3428,8 +3432,8 @@ int LDAPManager::setLDAPMasterReplicationSettings(LDAPMasterReplicationInfo repl haveOlcOverlaySyncProv = true; } } - - // clean up + + // Clean up ldap_msgfree(msg); if (!haveOlcOverlaySyncProv) { @@ -3478,8 +3482,8 @@ int LDAPManager::setLDAPMasterReplicationSettings(LDAPMasterReplicationInfo repl haveOlcOverlaySyncProv = true; } } - - // clean up + + // Clean up ldap_msgfree(msg); if (!haveOlcOverlaySyncProv) { @@ -3591,7 +3595,7 @@ int LDAPManager::getTDECertificate(TQString certificateName, TQString fileName, } } - // clean up + // Clean up ldap_msgfree(msg); return returncode; -- cgit v1.2.3