mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
Fix memory leak in Cache update method (#1143)
This commit is contained in:
@@ -831,10 +831,16 @@ impl<T: Clone + Debug + Send + 'static> Cache<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
async fn update(&self) -> std::io::Result<()> {
|
async fn update(&self) -> std::io::Result<()> {
|
||||||
match (self.update_fn)().await {
|
match (self.update_fn)().await {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
self.val.store(Box::into_raw(Box::new(val)), AtomicOrdering::SeqCst);
|
let old = self.val.swap(Box::into_raw(Box::new(val)), AtomicOrdering::SeqCst);
|
||||||
|
if !old.is_null() {
|
||||||
|
unsafe {
|
||||||
|
drop(Box::from_raw(old));
|
||||||
|
}
|
||||||
|
}
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("Time went backwards")
|
.expect("Time went backwards")
|
||||||
|
|||||||
Reference in New Issue
Block a user