Skip to content

Commit

Permalink
Fix fsevent crash (mutating array in iteration) (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr authored and passcod committed Nov 21, 2017
1 parent b574d4e commit b5672b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ impl FsEventWatcher {
unsafe {
let cf_path = cf::str_path_to_cfstring_ref(str_path);

let mut to_remove = Vec::new();
for idx in 0..cf::CFArrayGetCount(self.paths) {
let item = cf::CFArrayGetValueAtIndex(self.paths, idx);
if cf::CFStringCompare(item, cf_path, cf::kCFCompareCaseInsensitive) ==
cf::kCFCompareEqualTo {
cf::CFArrayRemoveValueAtIndex(self.paths, idx);
to_remove.push(idx);
}
}

for idx in to_remove.iter().rev() {
cf::CFArrayRemoveValueAtIndex(self.paths, *idx);
}
}
let p = if let Ok(canonicalized_path) = path.as_ref().canonicalize() {
canonicalized_path
Expand Down

0 comments on commit b5672b5

Please sign in to comment.