Skip to content

Commit 9de607f

Browse files
committed
chore: fix
1 parent 1d116f5 commit 9de607f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rust/cubestore/cubestore/benches/tracking_allocator.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)