File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
rust/cubestore/cubestore/benches Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,10 @@ impl TrackingAllocator {
8484 }
8585 } else {
8686 self . deallocations . fetch_add ( 1 , Ordering :: Relaxed ) ;
87- self . current_allocated . fetch_sub ( size, Ordering :: Relaxed ) ;
87+ // Use saturating_sub to prevent underflow
88+ let current = self . current_allocated . load ( Ordering :: Relaxed ) ;
89+ let new_current = current. saturating_sub ( size) ;
90+ self . current_allocated . store ( new_current, Ordering :: Relaxed ) ;
8891 }
8992 }
9093}
@@ -109,8 +112,9 @@ unsafe impl GlobalAlloc for TrackingAllocator {
109112 self . reallocations . fetch_add ( 1 , Ordering :: Relaxed ) ;
110113
111114 // Update counters: subtract old size, add new size
112- self . current_allocated
113- . fetch_sub ( layout. size ( ) , Ordering :: Relaxed ) ;
115+ let current = self . current_allocated . load ( Ordering :: Relaxed ) ;
116+ let after_sub = current. saturating_sub ( layout. size ( ) ) ;
117+ self . current_allocated . store ( after_sub, Ordering :: Relaxed ) ;
114118 self . total_allocated . fetch_add ( new_size, Ordering :: Relaxed ) ;
115119 let current = self
116120 . current_allocated
You can’t perform that action at this time.
0 commit comments