cleanup invalid pid in locking on modify
authorStefan Metzmacher <metze@samba.org>
Mon, 13 Feb 2012 14:46:15 +0000 (15:46 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:41:42 +0000 (18:41 +0200)
source3/locking/locking.c

index b9afd2392c46f973581e4d930cf8316837179b7c..d90e8c679b1cfc2d2bea9e7f4b5a3aafce9e4060 100644 (file)
@@ -669,6 +669,23 @@ static void fill_deferred_open_entry(struct share_mode_entry *e,
 static void add_share_mode_entry(struct share_mode_data *d,
                                 const struct share_mode_entry *entry)
 {
+       uint32_t i = 0;
+
+       while (i < d->num_share_modes) {
+               struct share_mode_entry *e = &d->share_modes[i];
+               if (e->pid.pid == UINT64_MAX &&
+                   e->pid.task_id == UINT32_MAX &&
+                   e->pid.vnn == UINT32_MAX &&
+                   e->pid.unique_id == UINT64_MAX) {
+                       *e = d->share_modes[d->num_share_modes-1];
+                       d->num_share_modes -= 1;
+                       d->modified = True;
+                       continue;
+               }
+
+               i += 1;
+       }
+
        ADD_TO_ARRAY(d, struct share_mode_entry, *entry,
                     &d->share_modes, &d->num_share_modes);
        d->modified = True;
@@ -747,6 +764,7 @@ static struct share_mode_entry *find_share_mode_entry(struct share_mode_data *d,
 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
 {
        struct share_mode_entry entry, *e;
+       uint32_t i = 0;
 
        /* Don't care about the pid owner being correct here - just a search. */
        fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
@@ -758,6 +776,22 @@ bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
        *e = lck->data->share_modes[lck->data->num_share_modes-1];
        lck->data->num_share_modes -= 1;
        lck->data->modified = True;
+
+       while (i < lck->data->num_share_modes) {
+               e = &lck->data->share_modes[i];
+
+               if (e->pid.pid == UINT64_MAX &&
+                   e->pid.task_id == UINT32_MAX &&
+                   e->pid.vnn == UINT32_MAX &&
+                   e->pid.unique_id == UINT64_MAX) {
+                       *e = lck->data->share_modes[lck->data->num_share_modes-1];
+                       lck->data->num_share_modes -= 1;
+                       continue;
+               }
+
+               i += 1;
+       }
+
        return True;
 }