fix(core): Free prepared ids that are never assigned (#10184)

This commit is contained in:
John Billings authored and GitHub committed 2026-09-02 16:16:36 -07:00
1 parent 73a7e97981
commit 2508e37a5e
2 files changed
+27 -1

No files matched your search

+1
View File
@@ -47,6 +47,7 @@ Bottom level categories:
#### General
- Explicitly implement `Send` and `Sync` in `wgpu-core` to reduce the risk of `recursion_limit` overflow. By @nazar-pc in [#9953](https://github.com/gfx-rs/wgpu/pull/9953)
- Fix a texture id leak when surface acquire returns no texture. By @jnb in [#10184](https://github.com/gfx-rs/wgpu/pull/10184).
## v30.0.1 (2026-08-21)
+26 -1
View File
@@ -63,6 +63,7 @@ impl<T: StorageItem> Registry<T> {
#[must_use]
pub(crate) struct FutureId<'a, T: StorageItem> {
id: Id<T::Marker>,
identity: &'a IdentityManager<T::Marker>,
data: &'a RwLock<Storage<T>>,
}
@@ -73,7 +74,17 @@ impl<T: StorageItem> FutureId<'_, T> {
pub fn assign(self, value: T) -> Id<T::Marker> {
let mut data = self.data.write();
data.insert(self.id, value);
self.id
// Assigned ids are freed by `Registry::remove`, not `Drop`.
let id = self.id;
core::mem::forget(self);
id
}
}
/// Free the id if it was never assigned, so that its index can be reused.
impl<T: StorageItem> Drop for FutureId<'_, T> {
fn drop(&mut self) {
self.identity.free(self.id);
}
}
@@ -87,6 +98,7 @@ impl<T: StorageItem> Registry<T> {
}
None => self.identity.process(),
},
identity: &self.identity,
data: &self.storage,
}
}
@@ -169,4 +181,17 @@ mod tests {
}
})
}
#[test]
fn dropped_ids_are_reused() {
let registry = Registry::new();
let fid = registry.prepare(None);
let index = fid.id.unzip().0;
drop(fid);
let fid = registry.prepare(None);
assert_eq!(fid.id.unzip().0, index);
fid.assign(Arc::new(TestData));
}
}