diff --git a/crates/napi/src/bindgen_runtime/module_register.rs b/crates/napi/src/bindgen_runtime/module_register.rs index aa4f3e8c..57c44861 100644 --- a/crates/napi/src/bindgen_runtime/module_register.rs +++ b/crates/napi/src/bindgen_runtime/module_register.rs @@ -47,28 +47,27 @@ impl PersistedPerInstanceVec { f(&mut []); } else { let inner = self.inner.load(Ordering::Relaxed); - let mut temp = unsafe { Vec::from_raw_parts(inner, length, length) }; + let mut temp = + std::mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(inner, length, length) }); f(temp.as_mut_slice()); // Inner Vec has been reallocated, so we need to update the pointer if temp.as_mut_ptr() != inner { self.inner.store(temp.as_mut_ptr(), Ordering::Relaxed); } self.length.store(temp.len(), Ordering::Relaxed); - std::mem::forget(temp); } } fn push(&self, item: T) { let length = self.length.load(Ordering::Relaxed); let inner = self.inner.load(Ordering::Relaxed); - let mut temp = unsafe { Vec::from_raw_parts(inner, length, length) }; + let mut temp = + std::mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(inner, length, length) }); temp.push(item); // Inner Vec has been reallocated, so we need to update the pointer if temp.as_mut_ptr() != inner { self.inner.store(temp.as_mut_ptr(), Ordering::Relaxed); } - std::mem::forget(temp); - self.length.fetch_add(1, Ordering::Relaxed); } }