Index: nsswitch/winbindd_ads.c =================================================================== --- nsswitch/winbindd_ads.c (revision 17457) +++ nsswitch/winbindd_ads.c (working copy) @@ -1029,11 +1029,7 @@ rc = ads_USN(ads, seq); if (!ADS_ERR_OK(rc)) { - - /* its a dead connection ; don't destroy it - through since ads_USN() has already done - that indirectly */ - + ads_destroy(&ads); domain->private_data = NULL; } return ads_ntstatus(rc); Index: libads/ldap.c =================================================================== --- libads/ldap.c (revision 17457) +++ libads/ldap.c (working copy) @@ -134,6 +134,7 @@ if ( !ads_cldap_netlogon( srv, ads->server.realm, &cldap_reply ) ) { DEBUG(3,("ads_try_connect: CLDAP request %s failed.\n", srv)); + SAFE_FREE( srv ); return False; } @@ -2178,15 +2179,20 @@ ADS_STATUS status; void *res; - status = ads_do_search_retry(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res); + status = ads_do_search(ads, "", LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res); if (!ADS_ERR_OK(status)) return status; if (ads_count_replies(ads, res) != 1) { + ads_msgfree(ads, res); return ADS_ERROR(LDAP_NO_RESULTS_RETURNED); } - ads_pull_uint32(ads, res, "highestCommittedUSN", usn); + if (!ads_pull_uint32(ads, res, "highestCommittedUSN", usn)) { + ads_msgfree(ads, res); + return ADS_ERROR(LDAP_NO_SUCH_ATTRIBUTE); + } + ads_msgfree(ads, res); return ADS_SUCCESS; } Index: libads/cldap.c =================================================================== --- libads/cldap.c (revision 17457) +++ libads/cldap.c (working copy) @@ -295,6 +295,7 @@ ret = send_cldap_netlogon(sock, realm, global_myname(), 6); if (ret != 0) { + close(sock); return False; } ret = recv_cldap_netlogon(sock, reply);