Skip to content

Commit e7f0974

Browse files
authored
Merge pull request #186 from elichai/2019-12-manualdrop
Wrap Secp256k1 from raw context in a ManuallyDrop
2 parents e3aaf00 + d2c4e5a commit e7f0974

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/context.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::marker::PhantomData;
2+
use core::mem::ManuallyDrop;
23
use ptr;
34
use ffi::{self, CPtr};
45
use ffi::types::{c_uint, c_void};
@@ -227,12 +228,12 @@ impl<'buf> Secp256k1<AllPreallocated<'buf>> {
227228
/// * The user must handle the freeing of the context(using the correct functions) by himself.
228229
/// * Violating these may lead to Undefined Behavior.
229230
///
230-
pub unsafe fn from_raw_all(raw_ctx: *mut ffi::Context) -> Secp256k1<AllPreallocated<'buf>> {
231-
Secp256k1 {
231+
pub unsafe fn from_raw_all(raw_ctx: *mut ffi::Context) -> ManuallyDrop<Secp256k1<AllPreallocated<'buf>>> {
232+
ManuallyDrop::new(Secp256k1 {
232233
ctx: raw_ctx,
233234
phantom: PhantomData,
234235
buf: ptr::null_mut::<[u8;0]>() as *mut [u8] ,
235-
}
236+
})
236237
}
237238
}
238239

@@ -259,12 +260,12 @@ impl<'buf> Secp256k1<SignOnlyPreallocated<'buf>> {
259260
/// * The user must handle the freeing of the context(using the correct functions) by himself.
260261
/// * This list *is not* exhaustive, and any violation may lead to Undefined Behavior.,
261262
///
262-
pub unsafe fn from_raw_signining_only(raw_ctx: *mut ffi::Context) -> Secp256k1<SignOnlyPreallocated<'buf>> {
263-
Secp256k1 {
263+
pub unsafe fn from_raw_signining_only(raw_ctx: *mut ffi::Context) -> ManuallyDrop<Secp256k1<SignOnlyPreallocated<'buf>>> {
264+
ManuallyDrop::new(Secp256k1 {
264265
ctx: raw_ctx,
265266
phantom: PhantomData,
266267
buf: ptr::null_mut::<[u8;0]>() as *mut [u8] ,
267-
}
268+
})
268269
}
269270
}
270271

@@ -291,11 +292,11 @@ impl<'buf> Secp256k1<VerifyOnlyPreallocated<'buf>> {
291292
/// * The user must handle the freeing of the context(using the correct functions) by himself.
292293
/// * This list *is not* exhaustive, and any violation may lead to Undefined Behavior.,
293294
///
294-
pub unsafe fn from_raw_verification_only(raw_ctx: *mut ffi::Context) -> Secp256k1<VerifyOnlyPreallocated<'buf>> {
295-
Secp256k1 {
295+
pub unsafe fn from_raw_verification_only(raw_ctx: *mut ffi::Context) -> ManuallyDrop<Secp256k1<VerifyOnlyPreallocated<'buf>>> {
296+
ManuallyDrop::new(Secp256k1 {
296297
ctx: raw_ctx,
297298
phantom: PhantomData,
298299
buf: ptr::null_mut::<[u8;0]>() as *mut [u8] ,
299-
}
300+
})
300301
}
301302
}

0 commit comments

Comments
 (0)