Merge pull request #7821 from jiangliu/storage-leak

agent: avoid possible leakage of storage device
This commit is contained in:
Jiang Liu
2023-09-02 12:40:40 +08:00
committed by GitHub
2 changed files with 8 additions and 0 deletions

View File

@@ -71,6 +71,10 @@ impl StorageState {
}
}
pub fn path(&self) -> &str {
self.device.path()
}
pub async fn ref_count(&self) -> u32 {
self.count.load(Ordering::Relaxed)
}

View File

@@ -103,6 +103,10 @@ pub async fn add_storages(
let path = storage.mount_point.clone();
let state = sandbox.lock().await.add_sandbox_storage(&path).await;
if state.ref_count().await > 1 {
let path = state.path();
if !path.is_empty() {
mount_list.push(path.to_string());
}
// The device already exists.
continue;
}