Fix erase

This commit is contained in:
Sergey Pepyakin 2019-07-08 11:27:05 +02:00
parent d04c634d48
commit 4abd32d2c6
1 changed files with 11 additions and 15 deletions

View File

@ -159,12 +159,8 @@ impl ByteBuf {
} }
pub fn erase(&mut self) -> Result<(), &'static str> { pub fn erase(&mut self) -> Result<(), &'static str> {
let cur_len = match self.mmap { let len = self.len();
// Nothing to do here... if len > 0 {
None => return Ok(()),
Some(Mmap { len: cur_len, .. }) => cur_len,
};
// The order is important. // The order is important.
// //
// 1. First we clear, and thus drop, the current mmap if any. // 1. First we clear, and thus drop, the current mmap if any.
@ -172,8 +168,8 @@ impl ByteBuf {
// //
// Otherwise we double the peak memory consumption. // Otherwise we double the peak memory consumption.
self.mmap = None; self.mmap = None;
self.mmap = Some(Mmap::new(cur_len)?); self.mmap = Some(Mmap::new(len)?);
}
Ok(()) Ok(())
} }
} }