s3: Fix EnumDomainAliases when no aliases are in LDAP
[samba.git] / source3 / passdb / pdb_ldap.c
index 249a990d25715cd6dd6a17e8a0f1c21429d75cd9..559b87cfde1ed5df4e62429ad1803d67a94bb53b 100644 (file)
@@ -4416,12 +4416,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;
 }
 
@@ -4464,6 +4458,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;