s3: Fix EnumDomainAliases when no aliases are in LDAP
[samba.git] / source3 / passdb / pdb_ldap.c
index aa60b7a6647898e1e15a0d1ecbfa932ac21f2233..db86a481544e83e2f008932d816f21b38560c46f 100644 (file)
@@ -4442,12 +4442,6 @@ static bool ldapsam_search_firstpage(struct pdb_search *search)
         }
         state->current_entry = ldap_first_entry(ld, state->entries);
 
-       if (state->current_entry == NULL) {
-               ldap_msgfree(state->entries);
-               state->entries = NULL;
-               return false;
-       }
-
        return True;
 }
 
@@ -4490,6 +4484,10 @@ static bool ldapsam_search_next_entry(struct pdb_search *search,
        bool result;
 
  retry:
+       if (state->current_entry == NULL) {
+               return false;
+       }
+
        if ((state->entries == NULL) && (state->pagedresults_cookie == NULL))
                return False;