Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions parity-util-mem/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "parity-util-mem"
version = "0.1.0"
version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/parity-common"
description = "Collection of memory related utilities"
license = "GPL-3.0"

[dependencies]
clear_on_drop = "0.2"
cfg-if = "0.1.6"
malloc_size_of_derive = "0.1.0"
dlmalloc = { version = "0.1", features = ["global"], optional = true }
Expand Down
39 changes: 0 additions & 39 deletions parity-util-mem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ extern crate alloc;

extern crate malloc_size_of_derive as malloc_size_derive;

use std::ops::{Deref, DerefMut};

use std::ptr;

cfg_if! {
if #[cfg(all(
Expand Down Expand Up @@ -91,42 +88,6 @@ pub use malloc_size::{
};
pub use allocators::MallocSizeOfExt;

/// Wrapper to zero out memory when dropped.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Memzero<T: AsMut<[u8]>> {
mem: T,
}

impl<T: AsMut<[u8]>> From<T> for Memzero<T> {
fn from(mem: T) -> Memzero<T> {
Memzero { mem }
}
}

impl<T: AsMut<[u8]>> Drop for Memzero<T> {
fn drop(&mut self) {
unsafe {
for byte_ref in self.mem.as_mut() {
ptr::write_volatile(byte_ref, 0)
}
}
}
}

impl<T: AsMut<[u8]>> Deref for Memzero<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.mem
}
}

impl<T: AsMut<[u8]>> DerefMut for Memzero<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.mem
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod test {
Expand Down