Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions zeroize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,17 @@ where
/// Ensures the entire capacity of the `Vec` is zeroed. Cannot ensure that
/// previous reallocations did not leave values on the heap.
fn zeroize(&mut self) {
// Zero the spare (uninitialized) capacity first, i.e. everything
// beyond `len`. This must happen before `clear()` resets `len` to 0,
// otherwise `spare_capacity_mut()` would cover the whole allocation
// and re-zero the initialized elements a second time below.
self.spare_capacity_mut().zeroize();

// Zeroize all the initialized elements.
self.iter_mut().zeroize();

// Set the Vec's length to 0 and drop all the elements.
// Set the Vec's length to 0 and drop all the (already-zeroized) elements.
self.clear();

// Zero the full capacity of `Vec`.
self.spare_capacity_mut().zeroize();
}
}

Expand Down