smbd: Simplify validate_lock_entries
authorVolker Lendecke <vl@samba.org>
Sun, 29 Jun 2014 09:36:24 +0000 (11:36 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 30 Jun 2014 20:28:15 +0000 (22:28 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
source3/locking/brlock.c

index ba26a99fedf01de928071903f02ad465e1d5e0b5..198d86054958b3aa1c773c58affe315739dda8e2 100644 (file)
@@ -1715,7 +1715,6 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
                                  bool keep_disconnected)
 {
        unsigned int i;
-       unsigned int num_valid_entries = 0;
        struct lock_struct *locks = *pplocks;
        unsigned int num_entries = *pnum_entries;
        TALLOC_CTX *frame;
@@ -1756,54 +1755,29 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
                return false;
        }
 
-       for (i = 0; i < num_entries; i++) {
+       i = 0;
+
+       while (i < num_entries) {
                if (exists[i]) {
-                       num_valid_entries++;
+                       i++;
                        continue;
                }
 
                if (keep_disconnected &&
                    server_id_is_disconnected(&ids[i]))
                {
-                       num_valid_entries++;
+                       i++;
                        continue;
                }
 
-               /* This process no longer exists - mark this
-                  entry as invalid by zeroing it. */
-               ZERO_STRUCTP(&locks[i]);
+               /* This process no longer exists */
+
+               brl_delete_lock_struct(locks, num_entries, i);
+               num_entries -= 1;
        }
        TALLOC_FREE(frame);
 
-       if (num_valid_entries != num_entries) {
-               struct lock_struct *new_lock_data = NULL;
-
-               if (num_valid_entries) {
-                       new_lock_data = talloc_array(
-                               mem_ctx, struct lock_struct,
-                               num_valid_entries);
-                       if (!new_lock_data) {
-                               DEBUG(3, ("malloc fail\n"));
-                               return False;
-                       }
-
-                       num_valid_entries = 0;
-                       for (i = 0; i < num_entries; i++) {
-                               struct lock_struct *lock_data = &locks[i];
-                               if (lock_data->context.smblctx &&
-                                               lock_data->context.tid) {
-                                       /* Valid (nonzero) entry - copy it. */
-                                       memcpy(&new_lock_data[num_valid_entries],
-                                               lock_data, sizeof(struct lock_struct));
-                                       num_valid_entries++;
-                               }
-                       }
-               }
-
-               TALLOC_FREE(*pplocks);
-               *pplocks = new_lock_data;
-               *pnum_entries = num_valid_entries;
-       }
+       *pnum_entries = num_entries;
 
        return True;
 }