diff --git a/src/atom.rs b/src/atom.rs index c02651b..89c9cdd 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -237,7 +237,8 @@ impl Drop for Atom { // Out of line to guide inlining. fn drop_slow(this: &mut Atom) { - DYNAMIC_SET + // We temporarily store the string in the stack to drop after releasing the lock + let _removed = DYNAMIC_SET .lock() .remove(this.unsafe_data.get() as *mut Entry); } diff --git a/src/dynamic_set.rs b/src/dynamic_set.rs index 229a79f..e99f0c8 100644 --- a/src/dynamic_set.rs +++ b/src/dynamic_set.rs @@ -85,7 +85,7 @@ impl Set { ptr } - pub(crate) fn remove(&mut self, ptr: *mut Entry) { + pub(crate) fn remove(&mut self, ptr: *mut Entry) -> Option> { let bucket_index = { let value: &Entry = unsafe { &*ptr }; debug_assert!(value.ref_count.load(SeqCst) == 0); @@ -97,12 +97,11 @@ impl Set { while let Some(entry_ptr) = current.as_mut() { let entry_ptr: *mut Entry = &mut **entry_ptr; if entry_ptr == ptr { - mem::drop(mem::replace(current, unsafe { - (*entry_ptr).next_in_bucket.take() - })); - break; + return mem::replace(current, unsafe { (*entry_ptr).next_in_bucket.take() }); } current = unsafe { &mut (*entry_ptr).next_in_bucket }; } + + None } }