File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -67,22 +67,21 @@ impl AddressAllocator {
6767 ) -> Result < RangeInclusive > {
6868 let constraint = Constraint :: new ( size, alignment, policy) ?;
6969 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" ) ;
7171 Ok ( allocated)
7272 }
7373
7474 /// Deletes the specified memory slot or returns `ResourceNotAvailable` if
7575 /// the node was not allocated before.
7676 pub fn free ( & mut self , key : & RangeInclusive ) -> Result < ( ) > {
7777 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" ) ;
7979 Ok ( ( ) )
8080 }
8181
8282 /// 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!
8685 pub fn used ( & self ) -> usize {
8786 self . used
8887 }
You can’t perform that action at this time.
0 commit comments