diff --git a/src/context.rs b/src/context.rs index 52402d0..d38ada8 100644 --- a/src/context.rs +++ b/src/context.rs @@ -212,7 +212,6 @@ mod alloc_only { ffi::secp256k1_context_preallocated_create(ptr as *mut c_void, C::FLAGS) }, phantom: PhantomData, - size, }; #[cfg(all( @@ -273,7 +272,6 @@ mod alloc_only { ffi::secp256k1_context_preallocated_clone(self.ctx, ptr as *mut c_void) }, phantom: PhantomData, - size, } } } @@ -329,7 +327,6 @@ impl<'buf, C: Context + 'buf> Secp256k1 { ) }, phantom: PhantomData, - size: 0, // We don't care about the size because it's the caller responsibility to deallocate. }) } } @@ -358,11 +355,7 @@ impl<'buf> Secp256k1> { pub unsafe fn from_raw_all( raw_ctx: *mut ffi::Context, ) -> ManuallyDrop>> { - ManuallyDrop::new(Secp256k1 { - ctx: raw_ctx, - phantom: PhantomData, - size: 0, // We don't care about the size because it's the caller responsibility to deallocate. - }) + ManuallyDrop::new(Secp256k1 { ctx: raw_ctx, phantom: PhantomData }) } } @@ -393,11 +386,7 @@ impl<'buf> Secp256k1> { pub unsafe fn from_raw_signing_only( raw_ctx: *mut ffi::Context, ) -> ManuallyDrop>> { - ManuallyDrop::new(Secp256k1 { - ctx: raw_ctx, - phantom: PhantomData, - size: 0, // We don't care about the size because it's the caller responsibility to deallocate. - }) + ManuallyDrop::new(Secp256k1 { ctx: raw_ctx, phantom: PhantomData }) } } @@ -428,10 +417,6 @@ impl<'buf> Secp256k1> { pub unsafe fn from_raw_verification_only( raw_ctx: *mut ffi::Context, ) -> ManuallyDrop>> { - ManuallyDrop::new(Secp256k1 { - ctx: raw_ctx, - phantom: PhantomData, - size: 0, // We don't care about the size because it's the caller responsibility to deallocate. - }) + ManuallyDrop::new(Secp256k1 { ctx: raw_ctx, phantom: PhantomData }) } } diff --git a/src/lib.rs b/src/lib.rs index 946f6c7..e03c0dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,7 +371,6 @@ impl std::error::Error for Error { pub struct Secp256k1 { ctx: *mut ffi::Context, phantom: PhantomData, - size: usize, } // The underlying secp context does not contain any references to memory it does not own. @@ -388,8 +387,9 @@ impl Eq for Secp256k1 {} impl Drop for Secp256k1 { fn drop(&mut self) { unsafe { + let size = ffi::secp256k1_context_preallocated_clone_size(self.ctx); ffi::secp256k1_context_preallocated_destroy(self.ctx); - C::deallocate(self.ctx as _, self.size); + C::deallocate(self.ctx as _, size); } } } @@ -556,13 +556,11 @@ mod tests { let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) }; let ctx_vrfy = unsafe { ffi::secp256k1_context_create(VerifyOnlyPreallocated::FLAGS) }; - let size = 0; - let full: Secp256k1 = - Secp256k1 { ctx: ctx_full, phantom: PhantomData, size }; + let full: Secp256k1 = Secp256k1 { ctx: ctx_full, phantom: PhantomData }; let sign: Secp256k1 = - Secp256k1 { ctx: ctx_sign, phantom: PhantomData, size }; + Secp256k1 { ctx: ctx_sign, phantom: PhantomData }; let vrfy: Secp256k1 = - Secp256k1 { ctx: ctx_vrfy, phantom: PhantomData, size }; + Secp256k1 { ctx: ctx_vrfy, phantom: PhantomData }; let (sk, pk) = full.generate_keypair(&mut rand::thread_rng()); let msg = Message::from_slice(&[2u8; 32]).unwrap();