From 80ffbe9fd8457cb4dce60db05d3e6635f3b00a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Wejdenst=C3=A5l?= Date: Mon, 24 Jun 2024 15:38:57 +0200 Subject: [PATCH] fix deadlock in shrink_to_fit --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ef2e6b56..1b0225a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1110,7 +1110,9 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S> fn _shrink_to_fit(&self) { self.shards.iter().for_each(|s| { - s.write().shrink_to(self.len(), |(k, _v)| { + let mut shard = s.write(); + let size = shard.len(); + shard.shrink_to(size, |(k, _v)| { let mut hasher = self.hasher.build_hasher(); k.hash(&mut hasher); hasher.finish()