File tree 1 file changed +4
-5
lines changed
1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -67,22 +67,21 @@ impl AddressAllocator {
67
67
) -> Result < RangeInclusive > {
68
68
let constraint = Constraint :: new ( size, alignment, policy) ?;
69
69
let allocated = self . interval_tree . allocate ( constraint) ?;
70
- self . used += allocated. len ( ) as usize ;
70
+ self . used . checked_add ( allocated. len ( ) as usize ) . expect ( "Failed to calculate used memory" ) ;
71
71
Ok ( allocated)
72
72
}
73
73
74
74
/// Deletes the specified memory slot or returns `ResourceNotAvailable` if
75
75
/// the node was not allocated before.
76
76
pub fn free ( & mut self , key : & RangeInclusive ) -> Result < ( ) > {
77
77
self . interval_tree . free ( key) ?;
78
- self . used -= key. len ( ) as usize ;
78
+ self . used . checked_sub ( key. len ( ) as usize ) . expect ( "Failed to calculate used memory" ) ;
79
79
Ok ( ( ) )
80
80
}
81
81
82
82
/// Returns the used memory size in this allocator.
83
- /// NOTE that due to fragmentations, it's not guaranteed that the next
84
- /// allocate() call after querying the used memory can succeed with
85
- /// allocating all unused memories and it may still return OOM.
83
+ /// NOTE that due to fragmentations, not all unused memory may be available
84
+ /// for next `allocate()` call!
86
85
pub fn used ( & self ) -> usize {
87
86
self . used
88
87
}
You can’t perform that action at this time.
0 commit comments