Skip to content

Commit 49edaf1

Browse files
committed
Fix in weak_count in Arc.
In the case the weak count was locked, the weak_count function could return usize::MAX. We need to test this condition manually.
1 parent 83c659e commit 49edaf1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/liballoc/arc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ impl<T: ?Sized> Arc<T> {
453453
#[inline]
454454
#[stable(feature = "arc_counts", since = "1.15.0")]
455455
pub fn weak_count(this: &Self) -> usize {
456-
this.inner().weak.load(SeqCst) - 1
456+
let cnt = this.inner().weak.load(SeqCst);
457+
// If the weak count is currently locked, the value of the
458+
// count was 0 just before taking the lock.
459+
if cnt == usize::MAX { 0 } else { cnt - 1 }
457460
}
458461

459462
/// Gets the number of strong (`Arc`) pointers to this value.

0 commit comments

Comments
 (0)