Skip to content

Commit

Permalink
♻️ Better error handling of Segment::reserve_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlm committed Sep 18, 2023
1 parent b1e97f3 commit a9dd3c2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ impl<T> Segment<T> {
// Extract address from inner struct.
// If one of the following call fail, it will avoid multiple free / accessing un-mapped region.
let addr = mem::replace(&mut self.addr, ptr::null_mut());
let capacity = mem::replace(&mut self.capacity, 0);
let len = mem::replace(&mut self.len, 0);

// unmap region
munmap(addr, self.capacity)?;
munmap(addr, capacity)?;

// Grow file
let file = OpenOptions::new()
Expand All @@ -246,6 +248,7 @@ impl<T> Segment<T> {
// Re-map region
self.addr = mmap(&file, new_capacity)?;
self.capacity = new_capacity;
self.len = len;
}

Ok(())
Expand Down

0 comments on commit a9dd3c2

Please sign in to comment.