From 705c641428be9862699bead26e0b2d2dca273782 Mon Sep 17 00:00:00 2001 From: Ollie Date: Thu, 13 Aug 2026 09:06:24 +0100 Subject: [PATCH] fix: correct synchronisation when dropping Arc and Weak --- stabby-abi/src/alloc/sync.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stabby-abi/src/alloc/sync.rs b/stabby-abi/src/alloc/sync.rs index af20e54..8a6a168 100644 --- a/stabby-abi/src/alloc/sync.rs +++ b/stabby-abi/src/alloc/sync.rs @@ -304,11 +304,12 @@ impl Drop for Arc { fn drop(&mut self) { if unsafe { self.ptr.prefix() } .strong - .fetch_sub(1, Ordering::Relaxed) + .fetch_sub(1, Ordering::Release) != 1 { return; } + core::sync::atomic::fence(Ordering::Acquire); unsafe { core::ptr::drop_in_place(self.ptr.as_mut()); _ = Weak::::from_raw(self.ptr); @@ -401,11 +402,12 @@ impl Drop for Weak { fn drop(&mut self) { if unsafe { self.ptr.prefix() } .weak - .fetch_sub(1, Ordering::Relaxed) + .fetch_sub(1, Ordering::Release) != 1 { return; } + core::sync::atomic::fence(Ordering::Acquire); unsafe { let mut alloc = self.ptr.prefix().alloc.assume_init_read(); self.ptr.free(&mut alloc)